- 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.
推薦閱讀
- Learning ASP.NET Core 2.0
- Python機器學(xué)習(xí)實戰(zhàn)
- PLC編程及應(yīng)用實戰(zhàn)
- Nexus規(guī)?;疭crum框架
- Flux Architecture
- Python數(shù)據(jù)結(jié)構(gòu)與算法(視頻教學(xué)版)
- 詳解MATLAB圖形繪制技術(shù)
- Android驅(qū)動開發(fā)權(quán)威指南
- Unity 3D/2D移動開發(fā)實戰(zhàn)教程
- Android傳感器開發(fā)與智能設(shè)備案例實戰(zhàn)
- PHP+MySQL動態(tài)網(wǎng)站開發(fā)從入門到精通(視頻教學(xué)版)
- WebStorm Essentials
- 軟件測試項目實戰(zhàn)之功能測試篇
- Prezi Cookbook
- Getting Started with SQL Server 2014 Administration