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

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.

主站蜘蛛池模板: 谢通门县| 博兴县| 东至县| 汶上县| 石泉县| 景宁| 达州市| 晋中市| 综艺| 遂宁市| 汉寿县| 兰坪| 怀安县| 泉州市| 繁峙县| 科技| 青河县| 阿瓦提县| 镇江市| 芷江| 长海县| 南江县| 新兴县| 宿松县| 宕昌县| 阿瓦提县| 双桥区| 镇原县| 泉州市| 陇西县| 南安市| 庄浪县| 墨脱县| 宜都市| 滨州市| 静安区| 滨海县| 岳阳市| 旬阳县| 民和| 岐山县|