コード例 #1
0
 private void OnTriggerEnter2D(Collider2D entity)
 {
     if (entity.tag != "Player")
     {
         return;
     }
     if (bonuses.Length <= 0)
     {
         Debug.Log("Error, there is no bonuses.");
     }
     else
     {
         Transform tr = animationInstance.transform;
         Animator  rd = tr.GetComponent <Animator>();
         rd.Play("30");
         GetComponent <Renderer>().enabled = false;
         GameObject        go    = Instantiate(bonuses[Random.Range(0, bonuses.Length)], transform.position, Quaternion.identity);
         CollectableObject bonus = go.GetComponent <CollectableObject>();
         bonus.UseEffect(entity.gameObject);
         DestroyAnim(tr);
         StartCoroutine(ShowMessage(bonus.description, entity.gameObject, 2.5f));
         return;
     }
     DestroyBonus();
 }
コード例 #2
0
    public void TakeObject(CollectableObject collectableObject)
    {
        if (!collectableObject.ObjectTaken)
        {
            int i = 0;
            while (i < Inventory.Length && Inventory[i] != null)
            {
                i++;
            }

            if (i < Inventory.Length)
            {
                Inventory[i] = collectableObject;

                if (collectableObject.BuffObject != null)
                {
                    Buffs.Add(collectableObject.BuffObject);
                }

                collectableObject.ObjectTaken = true;
                collectableObject.TakeObjectAnimation();
            }
            else
            {
                print("Inventory full");
            }
        }
    }
コード例 #3
0
    public void AddItemToInvanntory(CollectableObject obj)
    {
        if (objectsInInvantory.Count >= invantorySlots.Count)
        {
            return;
        }

        if (!objectsInInvantory.Find(x => x.itemLogic.name == obj.objectRefrence.name))
        {
            objectsInInvantory.Add(obj.objectRefrence);
            obj.objectRefrence.quantity = obj.quantity;
            invantorySlots [objectsInInvantory.Count - 1].GetComponent <InvantorySlot> ().SetItem(obj.objectRefrence.objectImage, obj.quantity);
        }
        else
        {
            int idx = objectsInInvantory.FindIndex(x => x.itemLogic.name == obj.objectRefrence.name);
            objectsInInvantory [idx].quantity += obj.quantity;
            invantorySlots [idx].GetComponent <InvantorySlot> ().SetItem(objectsInInvantory [idx].objectImage, objectsInInvantory [idx].quantity);
        }

        if (useTooltip)
        {
            if (currentlySelectedItem >= 0 && currentlySelectedItem < objectsInInvantory.Count)
            {
                tooltipText.text = objectsInInvantory [currentlySelectedItem].objectTooltip;
            }
            else
            {
                tooltipText.text = "";
            }
        }
        UpdateEquipped();
    }
コード例 #4
0
 public void DropObject(CollectableObject target, Vector3 pos)
 {
     this.objectToDrop = target;
     targetPosition    = pos;
     moveScript.Move(pos);
     onTheMove = true;
 }
コード例 #5
0
 public void RemoveObject(CollectableObject collectableObject)
 {
     if (collectableObject.BuffObject != null)
     {
         Buffs.Remove(collectableObject.BuffObject);
     }
 }
コード例 #6
0
 public void StopAction()
 {
     objectToTake = null;
     onTheMove    = false;
     moveScript.StopAction();
     targetPosition = Vector3.zero;
     objectToDrop   = null;
 }
コード例 #7
0
ファイル: PickerPool.cs プロジェクト: tiyago1/RollicCase
    private void OnTriggerExit(Collider collider)
    {
        CollectableObject collectableObject = collider.GetComponent <CollectableObject>();

        if (collectableObject != null)
        {
            poolOfCollectableObject.Remove(collectableObject);
        }
    }
コード例 #8
0
 /// <summary>
 /// spawn a collectable in a random location
 /// </summary>
 public void SpawnCollectable()
 {
     if (_spawnedCount < MaxSpawnAmount)
     {
         Vector3           rand = new Vector3(Random.insideUnitCircle.x * SizeOfArena, Random.insideUnitCircle.y * SizeOfArena, 0);
         CollectableObject go   = Instantiate(ObjectToSpawn, rand, Quaternion.identity);
         go.OnPickUp += LowerSpawnCount;
         _spawnedCount++;
     }
 }
コード例 #9
0
    private void OnCollisionEnter(Collision collision)
    {
        CollectableObject collectableObject = collision.gameObject.GetComponent <CollectableObject>();

        if (collectableObject != null)
        {
            collectableObject.Reset();
            AddScore();
        }
    }
コード例 #10
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.GetComponent <CollectableObject>() != null)
     {
         CollectableObject _Collectable = collision.gameObject.GetComponent <CollectableObject>();
         playerScore += _Collectable.scorePoints;
         OnPlayerScoreHandler?.Invoke(playerId, playerScore); // Send event signal to UI that gets point on collision
         _getPointSFX.Play();
         Destroy(collision.gameObject);
     }
 }
コード例 #11
0
ファイル: Shop.cs プロジェクト: bigfootledur/JeuVideoUnity
    public void SellObject(CollectableObject objectToSell)
    {
        WalkingUnit buyer = TriggerShop.GetNearestOne();

        if (buyer == null)
        {
            print("Nobody is near");
            return;
        }

        if (!buyer.faction.Equals(GameMaster.PlayerFaction))
        {
            return;
        }

        if (buyer)
        {
            if (buyer && buyer.HasInventory() &&
                (buyer.faction.Equals(Faction.Blue) && (gameMaster.BlueWool >= objectToSell.MoneyCost)) ||
                (buyer.faction.Equals(Faction.Red) && (gameMaster.RedWool >= objectToSell.MoneyCost)))
            {
                bool objectSold = false;
                for (int i = 0; i < buyer.Inventory.Length; i++)
                {
                    if (buyer.Inventory[i] == null)
                    {
                        if (buyer.faction.Equals(Faction.Blue) && (gameMaster.BlueWool >= objectToSell.MoneyCost))
                        {
                            gameMaster.BlueWool -= objectToSell.MoneyCost;
                        }
                        else if (buyer.faction.Equals(Faction.Red) && (gameMaster.RedWool >= objectToSell.MoneyCost))
                        {
                            gameMaster.RedWool -= objectToSell.MoneyCost;
                        }
                        else
                        {
                            Debug.LogError("Couldn't take money from red/blue wool when selling " + objectToSell + " to " + buyer.gameObject);
                        }

                        CollectableObject obj = Instantiate(objectToSell);
                        obj.gameObject.SetActive(false);
                        buyer.TakeObject(obj);
                        objectSold = true;
                        break;
                    }
                }
                if (!objectSold)
                {
                    print("Inventory full");
                }
            }
        }
    }
コード例 #12
0
ファイル: LevelManager.cs プロジェクト: tiyago1/RollicCase
    public void SetupLevel(int levelIndex)
    {
        this.levelIndex  = levelIndex;
        currentLevelData = allLevelData[levelIndex];
        currentPlatforms = new List <Platform>();

        foreach (PlatformData platformData in currentLevelData.Platforms)
        {
            Platform platform = poolManager.PlatformPool.Allocate();
            platform.gameObject.SetActive(true);
            platform.Initialize(platformData);
            currentPlatforms.Add(platform);
        }

        for (int i = 0; i < currentLevelData.ObjectsData.Count; i++)
        {
            Platform currentPlatform = currentPlatforms[currentLevelData.ObjectsData[i].PlatformIndex];
            CollectableObjectGroup collectableObjectGroup = poolManager.CollectableObjectGroupPool.Allocate();

            collectableObjectGroup.gameObject.SetActive(true);
            collectableObjectGroup.Initialize(currentLevelData.ObjectsData[i].Position, currentPlatform.transform);
            currentPlatform.platformElements.Add(collectableObjectGroup);
            currentCollectableObjectGroup.Add(collectableObjectGroup);

            if (currentLevelData.ObjectsData[i].PresetData != null)
            {
                ApplyPresetToCollectableObject(currentLevelData.ObjectsData[i], collectableObjectGroup);
            }
        }

        for (int i = 0; i < currentLevelData.HelicopterData.Count; i++)
        {
            Platform   currentPlatform = currentPlatforms[currentLevelData.HelicopterData[i].PlatformIndex];
            Helicopter helicopter      = poolManager.HelicopterPools.Allocate();
            Pool <CollectableObject> collectableObjectPool = poolManager.GetCollectableObjectPool(currentLevelData.HelicopterData[i].ObjectType);
            List <CollectableObject> collectableObjects    = new List <CollectableObject>();

            foreach (PlatformObjectData objectData in currentLevelData.HelicopterData[i].ObjectData)
            {
                CollectableObject collectableObject = collectableObjectPool.Allocate();
                collectableObject.Initialize(Vector3.zero, ObjectType.Ball, currentPlatform.transform);
                collectableObjects.Add(collectableObject);
            }

            currentPlatform.platformElements.AddRange(collectableObjects);
            currentCollectableObjects.AddRange(collectableObjects);
            helicopter.gameObject.SetActive(true);
            helicopter.Initialize(collectableObjects, currentLevelData.HelicopterData[i], currentPlatform.transform);
            currentHelicopters.Add(helicopter);
            currentPlatform.platformElements.Add(helicopter);
        }
    }
コード例 #13
0
    public void SendDropItemOrder(CollectableObject collectableObject, Vector3 position, bool directOrder, bool postpone)
    {
        if (!postpone)
        {
            if (directOrder)
            {
                Orders.Clear();
            }

            SendMessage("StopAction");
            CollectableObjectScript.DropObject(collectableObject, position);
        }
    }
コード例 #14
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "HideSpot")
        {
            hideSpot = other.gameObject.GetComponent <HideAbleObject>();
        }

        if (other.gameObject.tag == "Money")
        {
            CollectableObject.CollectMoney(V);
            Destroy(other.gameObject);
            Debug.Log("error");
        }
    }
コード例 #15
0
 /// <summary>
 /// spawn a collectable in a specific location
 /// </summary>
 /// <param name="position"></param> where it will spawn
 /// <param name="overflow></param> will it overflow?
 public void SpawnCollectable(Vector2 position, bool overflow = true)
 {
     if (overflow)
     {
         CollectableObject go = Instantiate(ObjectToSpawn, position, Quaternion.identity);
         go.OnPickUp += LowerSpawnCount;
     }
     else if (_spawnedCount < MaxSpawnAmount)
     {
         CollectableObject go = Instantiate(ObjectToSpawn, position, Quaternion.identity);
         go.OnPickUp += LowerSpawnCount;
         _spawnedCount++;
     }
 }
コード例 #16
0
    IEnumerator PickupWithDelay(ControllerColliderHit hit)
    {
        CollectableObject collectable = hit.gameObject.GetComponent <CollectableObject>();

        if (collectable != null)
        {
            collectable.Collect(this);
        }

        canCollect = false;
        yield return(collectionDelay);

        canCollect = true;
    }
コード例 #17
0
ファイル: LevelManager.cs プロジェクト: tiyago1/RollicCase
 private void ApplyPresetToCollectableObject(PlatformObjectData platformObjectData, CollectableObjectGroup collectableObjectGroup)
 {
     foreach (Vector3 point in platformObjectData.PresetData.Positions)
     {
         Pool <CollectableObject> collectableObjectPool = poolManager.GetCollectableObjectPool(platformObjectData.ObjectType);
         CollectableObject        collectableObject     = collectableObjectPool.Allocate();
         collectableObject.gameObject.SetActive(true);
         collectableObject.Initialize(point, platformObjectData.ObjectType, collectableObjectGroup.transform);
         currentPlatforms[platformIndex].platformElements.Add(collectableObjectGroup);
         currentPlatforms[platformIndex].platformElements.Add(collectableObject);
         currentCollectableObjects.Add(collectableObject);
         currentCollectableObjectGroup.Add(collectableObjectGroup);
     }
 }
コード例 #18
0
    public IEnumerator SpawnCollectableAtPlayerLocationCo(GameObject player)
    {
        for (int i = 0; i < playerBoostSpawnAmount; i++)
        {
            CollectableObject go = Instantiate(ObjectToSpawn, player.transform.position, Quaternion.identity);
            go.gameObject.SetActive(false);

            yield return(new WaitForSeconds(playerBoostSpawnDelay));

            go.gameObject.SetActive(true);
            go.OnPickUp += LowerSpawnCount;
        }

        boostSpawnCo = null;
    }
コード例 #19
0
    public void GoTakeObject(CollectableObject collectableObject)
    {
        int i = 0;

        while (i < Inventory.Length && Inventory[i] != null)
        {
            i++;
        }

        if (i < Inventory.Length)
        {
            CollectableObjectScript.TakeObject(collectableObject);
        }
        else
        {
            print("Inventory full");
        }
    }
コード例 #20
0
    protected override void Awake()
    {
        base.Awake();
        for (int i = 0; i < LevelsSkill.Length; i++)
        {
            LevelsSkill[i] = -1;
        }
        Inventory = new CollectableObject[6];

        for (int i = 0; i < Inventory.Length; i++)
        {
            Inventory[i] = null;
        }

        UpdateExperiencePointsDisplay();
        UpdateSkillAvailableDisplay();
        UpdateNewSkillButtonsDisplay();
        hasPassiveSkill = HasPassiveSkill();
    }
コード例 #21
0
    public void launchObjects()
    {
        for (int x = 0; x < mapSizeX; x++)
        {
            for (int y = 0; y < mapSizeX; y++)
            {
                if (((tiles[x, y] != 6) && (tiles[x, y] != 7)) || ((x == selectedUnit.transform.position.x) && (y == selectedUnit.transform.position.y)))
                {
                    continue;
                }
                CollectableObjectType tt = myCollectable;
                GameObject            go = (GameObject)Instantiate(tt.tileVisualPrefab, new Vector3(x, y, -1), Quaternion.identity);

                CollectableObject ct = go.GetComponent <CollectableObject>();
                ct.tileX = x;
                ct.tileY = y;
                ct.map   = this;
            }
        }
        Debug.Log("objects made");
    }
コード例 #22
0
    public void EquipItem(InvantoryObject obj, Transform hand)
    {
        //Debug.Log ("Equipping inventory object " + obj);
        GameObject newObj = GameObject.Instantiate(obj.objectPrefab, Vector3.zero, hand.rotation, hand) as GameObject;

        newObj.gameObject.transform.localPosition = Vector3.zero;
        CollectableObject collectable = obj.objectPrefab.GetComponent <CollectableObject> ();

        hand.localRotation = Quaternion.Euler(collectable.offsetXRot, collectable.offsetYRot, collectable.offsetZRot);

        // disable rigidbody
        Rigidbody rb = newObj.GetComponent <Rigidbody> ();

        rb.useGravity       = false;
        rb.isKinematic      = true;
        rb.detectCollisions = false;

        newObj.gameObject.GetComponent <Light> ().enabled = false;
        if (equipType == EquipType.Custom)
        {
            newObj.GetComponent <RuntimeEquipLogic> ().Equip(newObj);
        }
    }
コード例 #23
0
    public void DropObject(CollectableObject collectableObject, Vector3 pos)
    {
        for (int i = 0; i < Inventory.Length; i++)
        {
            if (Inventory[i] != null)
            {
                if (Inventory[i].Equals(collectableObject))
                {
                    if (Inventory[i].GetComponent <CollectableObject>().BuffObject != null)
                    {
                        Buffs.Remove(Inventory[i].GetComponent <CollectableObject>().BuffObject);
                    }

                    Inventory[i] = null;
                    break;
                }
            }
        }
        collectableObject.transform.position   = new Vector3(pos.x, 11, pos.z);
        collectableObject.transform.localScale = new Vector3(1, 1, 1);
        collectableObject.ObjectTaken          = false;
        collectableObject.gameObject.SetActive(true);
    }
コード例 #24
0
    // Called regardless of if there are non-kinematic RigidBody's involved
    private void ProcessCollision(GameObject otherGameObject)
    {
        if (otherGameObject.layer == LayerMask.NameToLayer("BaseLevel"))
        {
        }
        else if (otherGameObject.layer == LayerMask.NameToLayer("Props"))
        {
        }
        else if (otherGameObject.layer == LayerMask.NameToLayer("Enemies"))
        {
            DamageObject damageObj = otherGameObject.GetComponentInParent <DamageObject>();
            if (damageObj != null)
            {
                if (GameCoordinator.Instance.Health > 0)
                {
                    GameCoordinator.Instance.Health -= damageObj.Value;
                    if (GameCoordinator.Instance.Health <= 0)
                    {
                        GameCoordinator.Instance.Health = 0;
                    }

                    Debug.Log($"Took damage {damageObj.Value} from enemy {otherGameObject.name}");

                    CheckWinLossConditions();
                }
            }
        }
        else if (otherGameObject.layer == LayerMask.NameToLayer("Player"))
        {
        }
        else if (otherGameObject.layer == LayerMask.NameToLayer("Collectables"))
        {
            if (!m_IsGameOver)
            {
                CollectableObject co = otherGameObject.GetComponentInParent <CollectableObject>();
                if (co != null)
                {
                    GameCoordinator.Instance.Health += co.RechargeValue;
                    GameCoordinator.Instance.Ammo   += co.AmmoValue;

                    if (co.IsLevelToken)
                    {
                        m_LevelTokens.Add(otherGameObject.name);
                    }
                }

                Debug.Log("Collected " + otherGameObject.name);
                Destroy(otherGameObject);

                CheckWinLossConditions();
            }
        }
        else if (otherGameObject.layer == LayerMask.NameToLayer("PlayerProjectiles"))
        {
        }
        else if (otherGameObject.layer == LayerMask.NameToLayer("EnemyProjectiles"))
        {
            DamageObject damageObj = otherGameObject.GetComponentInParent <DamageObject>();
            if (damageObj != null)
            {
                if (GameCoordinator.Instance.Health > 0)
                {
                    GameCoordinator.Instance.Health -= damageObj.Value;
                    if (GameCoordinator.Instance.Health <= 0)
                    {
                        GameCoordinator.Instance.Health = 0;
                    }

                    Debug.Log($"Took damage {damageObj.Value} from projectile {otherGameObject.name}");

                    CheckWinLossConditions();
                }
            }
        }
    }
コード例 #25
0
 public void MonsterWasSelected(CollectableObject monster)
 {
     selectedMonster = monster;
 }
コード例 #26
0
 public void Collect(CollectableObject collectable)
 {
     collections.Add(collectable);
     GetComponent <MessageWriter>().WriteMessage(collectable.interactText);
 }
コード例 #27
0
 public void SendDirectDropItemOrder(CollectableObject collectableObject, Vector3 position)
 {
     SendDropItemOrder(collectableObject, position, true, false);
 }
コード例 #28
0
 public void Add(CollectableObject c)
 {
     collectables.Add(c);
 }
コード例 #29
0
 public void RemoveCollection(CollectableObject collectable)
 {
     m_collectables.Remove(collectable);
     collectable.gameObject.SetActive(false);
     Destroy(collectable.gameObject, 2f);
 }
コード例 #30
0
 public void AddCollection(CollectableObject collectable)
 {
     m_collectables.Add(collectable);
     collectable.gameObject.transform.SetParent(m_Collectable.transform);
 }