- Unity 2017 Game Optimization(Second Edition)
- Chris Dickinson
- 106字
- 2021-07-02 23:21:10
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.
推薦閱讀
- 樂學Web編程:網站制作不神秘
- Python金融數據分析
- 3D少兒游戲編程(原書第2版)
- Linux Device Drivers Development
- 利用Python進行數據分析(原書第3版)
- 軟件測試技術指南
- Getting Started with Nano Server
- Android移動應用開發項目教程
- 深入實踐DDD:以DSL驅動復雜軟件開發
- Visual Basic語言程序設計上機指導與練習(第3版)
- Blender 3D Cookbook
- 軟件再工程:優化現有軟件系統的方法與最佳實踐
- Learning Swift
- PHP從入門到精通(微視頻精編版)
- Modern R Programming Cookbook