Exemple #1
0
    private void MoveDrops(List <Vector3> myInitialPositions, List <GameObject> instancedDrops)
    {
        for (int i = 0; i < instancedDrops.Count; i++)
        {
            if (instancedDrops[i].GetComponent <Coin>() != null)
            {
                instancedDrops[i].GetComponent <Coin>().Tangible = false;
            }
            if (instancedDrops[i].GetComponent <Key>() != null)
            {
                instancedDrops[i].GetComponent <Key>().Tangible = false;
            }
            switch (instancedDrops[i].GetComponent <LootTable>().GetItemType())
            {
            case LootTable.ItemType.BrownCoin: BrownCoin(i); break;

            case LootTable.ItemType.PurpleCoin: PurpleCoin(i); break;

            case LootTable.ItemType.Key: Key(i); break;
            }
        }
        void Key(int i)
        {
            StartCoroutine(MoveOverTime(instancedDrops[i], myInitialPositions[i], 1f));
            instancedDrops[i].transform.SetParent(m_KeysContainer.transform);
            StartCoroutine(DelayHandler.DelayAction(1, () => instancedDrops[i].GetComponent <Key>().Tangible = true));
        }

        void PurpleCoin(int i)
        {
            StartCoroutine(MoveOverTime(instancedDrops[i], myInitialPositions[i], 1f));
            instancedDrops[i].transform.SetParent(m_CoinsContainer.transform);
            StartCoroutine(DelayHandler.DelayAction(1, () => instancedDrops[i].GetComponent <Coin>().Tangible = true));
        }

        // TODO: This.
        IEnumerator MoveOverTime(GameObject gameObject, Vector3 targetPosition, float durationInSeconds)
        {
            float   timer           = 0f;
            Vector3 initialPosition = gameObject.transform.position;

            while (gameObject.transform.position != targetPosition)
            {
                gameObject.transform.position = Vector3.Lerp(initialPosition, targetPosition, timer);
                timer += Time.deltaTime / durationInSeconds;
                yield return(null);
            }
        }

        void BrownCoin(int i)
        {
            Rigidbody2D rb = instancedDrops[i].AddComponent <Rigidbody2D>();

            instancedDrops[i].AddComponent <Magnet>();
            BoxCollider2D boxTriggerCollider2D = instancedDrops[i].GetComponent <BoxCollider2D>();

            GameObject container = new GameObject();

            container.transform.parent = instancedDrops[i].transform;
            container.layer            = 29; // The layer that only interacts with tiles/barriers/water
            BoxCollider2D myTileCollider = container.AddComponent <BoxCollider2D>();

            myTileCollider.transform.position = instancedDrops[i].transform.position;
            myTileCollider.size = instancedDrops[i].GetComponent <BoxCollider2D>().size;

            rb.useAutoMass = true;
            rb.constraints = RigidbodyConstraints2D.FreezeRotation;
            instancedDrops[i].transform.parent = m_CoinsContainer.transform;
            if (i % 2 == 0)
            {
                rb.AddForce(new Vector2((brownCoinCount) * 4, 60));
            }
            else
            {
                rb.AddForce(new Vector2(-(brownCoinCount) * 4, 60));
            }
            brownCoinCount++;
            StartCoroutine(DelayHandler.DelayAction(1, () => instancedDrops[i].GetComponent <Coin>().Tangible = true));
        }
    }
Exemple #2
0
 public void Died()
 {
     m_PlayerMovement.enabled = false;
     StartCoroutine(DelayHandler.DelayAction(2f, () => SceneHandler.ReloadCurrentScene()));
 }