Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. public class Unit : MonoBehaviour {
  2.  
  3. public event System.Action OnSpawn;
  4. //public event System.Action OnDeath;
  5.  
  6. void Start () {
  7. if (OnSpawn != null)
  8. OnSpawn ();
  9. }
  10. }
  11.  
  12. public class Spawner : MonoBehaviour {
  13. UnitManager unitManager;
  14.  
  15. void Start () {
  16. unitManager = FindObjectOfType<UnitManager>();
  17. }
  18. public void SpawnAxeman(int amount)
  19. {
  20. Unit spawned = Instantiate(AxemanPrefab, spawnPosition.position, spawnPosition.rotation)as Unit;
  21. spawned.OnSpawn += unitManager.OnUnitSpawn; //unit manager needs to listen for the spawn event from the unit.
  22. }
  23. }
  24.  
  25. public class UnitManager : MonoBehaviour {
  26. public void OnUnitSpawn() //listens to the event of units spawning
  27. {
  28. Debug.Log ("event sys working i know unit spawned, but no ref!");
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement