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

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.

主站蜘蛛池模板: 齐齐哈尔市| 长治县| 精河县| 松江区| 大厂| 凌海市| 阳曲县| 阿克陶县| 五寨县| 娱乐| 讷河市| 平遥县| 阳曲县| 望江县| 新干县| 故城县| 松滋市| 寿宁县| 罗江县| 娄底市| 彭山县| 肇庆市| 白河县| 德钦县| 普宁市| 山阴县| 金湖县| 乾安县| 大安市| 丽水市| 澄江县| 红桥区| 潼南县| 阿克陶县| 怀柔区| 岳阳市| 潞城市| 天等县| 鄂尔多斯市| 乳源| 锡林浩特市|