Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Unit : MonoBehaviour {
- public event System.Action OnSpawn;
- //public event System.Action OnDeath;
- void Start () {
- if (OnSpawn != null)
- OnSpawn ();
- }
- }
- public class Spawner : MonoBehaviour {
- UnitManager unitManager;
- void Start () {
- unitManager = FindObjectOfType<UnitManager>();
- }
- public void SpawnAxeman(int amount)
- {
- Unit spawned = Instantiate(AxemanPrefab, spawnPosition.position, spawnPosition.rotation)as Unit;
- spawned.OnSpawn += unitManager.OnUnitSpawn; //unit manager needs to listen for the spawn event from the unit.
- }
- }
- public class UnitManager : MonoBehaviour {
- public void OnUnitSpawn() //listens to the event of units spawning
- {
- Debug.Log ("event sys working i know unit spawned, but no ref!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement