Message sending

To send one of these message objects, we simply need to call either QueueEvent() or TriggerEvent() and pass it an instance of the message we wish to send. The following code demonstrates how we would broadcast a CreateEnemyMessage object when the spacebar is pressed:

public class EnemyCreatorComponent : MonoBehaviour {
void Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
MessagingSystem.Instance.QueueMessage(new CreateEnemyMessage());
}
}
}

If we were to test this code right now, nothing would happen, because even though we are sending a message through the messaging system, there are no listeners for this message type. Let's cover how to register listeners with the messaging system.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.30.232