private void OnDestroy() { if (_instance == this) { _instance = null; } }
public void DeSpawnPickup() { if (spawnedPickup == null) { return; } spawnedPickup.PickedUp -= SpawnedPickup_PickedUp; PickupManager.PoolPickup(spawnedPickup); spawnedPickup = null; }
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); } }
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); }
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; }