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

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.

主站蜘蛛池模板: 铜鼓县| 新巴尔虎右旗| 呼和浩特市| 怀安县| 都江堰市| 台南市| 奉贤区| 屏山县| 巴青县| 莎车县| 舟曲县| 武安市| 工布江达县| 元朗区| 云龙县| 全州县| 水富县| 林周县| 三台县| 三台县| 高唐县| 宁明县| 巢湖市| 昌江| 延津县| 北宁市| 蒲城县| 庐江县| 共和县| 武城县| 甘孜| 鹤山市| 行唐县| 南宁市| 读书| 西华县| 上高县| 长顺县| 沙湾县| 白山市| 牡丹江市|