コード例 #1
0
 private void OnDestroy()
 {
     if (_instance == this)
     {
         _instance = null;
     }
 }
コード例 #2
0
 public void DeSpawnPickup()
 {
     if (spawnedPickup == null)
     {
         return;
     }
     spawnedPickup.PickedUp -= SpawnedPickup_PickedUp;
     PickupManager.PoolPickup(spawnedPickup);
     spawnedPickup = null;
 }
コード例 #3
0
        private void Awake()
        {
            if (_instance == null)
            {
                _instance = this;

                for (int i = 0; i < 20; i++)
                {
                    PoolPickup(pickups.GetRandomPickup());
                    pooledPickups[i].transform.SetParent(transform);
                }

                audioSource = GetComponent <AudioSource>();
            }
            else
            {
                Destroy(gameObject);
            }
        }
コード例 #4
0
        private void OnTriggerEnter2D(Collider2D collision)
        {
            if (pickedUp)
            {
                return;
            }
            pickedUp = true;
            Player p = collision.gameObject.GetComponent <Player>();

            if (p != null)
            {
                p.SetCurrentFunds(p.CurrentFunds + pickupValue);
                UIManager.Instance.BroadCastHighImpact(p.Index, itemDescription, (pickupValue > 0));
                PickupManager.Instance.PlaySound(pickupValue > 0);
            }

            OnPickedUp();
            PickupManager.PoolPickup(this);
        }
コード例 #5
0
        public void SpawnPickup(int forIndex)
        {
            DeSpawnPickup();
            spawnedPickup = PickupManager.ActivatePickup();
            switch (forIndex)
            {
            case 0:
                spawnedPickup.SetLayer(LayerMask.NameToLayer("P1Pickups"));
                break;

            case 1:
                spawnedPickup.SetLayer(LayerMask.NameToLayer("P2Pickups"));
                break;

            default:
                break;
            }
            Vector3 newPos = new Vector3(botSpawnRange.position.x, UnityEngine.Random.Range(botSpawnRange.position.y, topSpawnRange.position.y), botSpawnRange.position.z);

            spawnedPickup.transform.position = newPos;
            spawnedPickup.PickedUp          += SpawnedPickup_PickedUp;
        }