void Spawn() { Vector3 attemptedSpawnLocation = new Vector3(); while (!AttemptSpawnLocation(ref attemptedSpawnLocation)) { } GameObject spawnedObject = Instantiate(objectToSpawn, attemptedSpawnLocation, Quaternion.identity); if (canOnlyHaveOne) { objectInScene = true; CollectableEventFirer eventFirer = spawnedObject.GetComponent <CollectableEventFirer>(); if (eventFirer) { eventFirer.onCollection += OnObjectCollected; } } }
private void Awake() { collider = GetComponent <Collider2D>(); collectableEventFirer = GetComponent <CollectableEventFirer>(); }