- Unity Game Optimization
- Dr. Davide Aversa Chris Dickinson
- 105字
- 2021-06-24 12:13:06
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.
推薦閱讀
- Boost程序庫完全開發指南:深入C++”準”標準庫(第5版)
- Microsoft Exchange Server PowerShell Cookbook(Third Edition)
- Monkey Game Development:Beginner's Guide
- 算法精粹:經典計算機科學問題的Java實現
- Python計算機視覺編程
- Mastering Scientific Computing with R
- PHP網絡編程學習筆記
- 深入理解Elasticsearch(原書第3版)
- AppInventor實踐教程:Android智能應用開發前傳
- Hadoop 2.X HDFS源碼剖析
- Greenplum構建實時數據倉庫實踐
- 快樂編程:青少年思維訓練
- jQuery Mobile Web Development Essentials(Second Edition)
- 例解Python:Python編程快速入門踐行指南
- Web前端開發精品課:HTML5 Canvas開發詳解