官术网_书友最值得收藏!

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 Space Bar 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.

主站蜘蛛池模板: 宁国市| 九江市| 汽车| 延津县| 丹寨县| 当涂县| 沙坪坝区| 体育| 梨树县| 东明县| 孝昌县| 民乐县| 清原| 吴川市| 香格里拉县| 都江堰市| 安岳县| 浦东新区| 土默特右旗| 湘潭市| 克什克腾旗| 德化县| 新化县| 嘉峪关市| 沾益县| 平江县| 克拉玛依市| 新平| 陆良县| 白玉县| 公主岭市| 纳雍县| 洛浦县| 桃园县| 宁海县| 沈阳市| 延寿县| 汤阴县| 京山县| 安岳县| 长治县|