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

  • 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.

主站蜘蛛池模板: 浮梁县| 连州市| 大悟县| 湖南省| 岳普湖县| 枝江市| 仁寿县| 龙游县| 炉霍县| 尼勒克县| 吉水县| 呼图壁县| 绥棱县| 清水县| 黄冈市| 德昌县| 嘉定区| 漾濞| 上高县| 吴堡县| 抚松县| 龙里县| 安远县| 乌鲁木齐市| 乐平市| 黄梅县| 廉江市| 荔波县| 大荔县| 秭归县| 广水市| 汝城县| 原平市| 穆棱市| 岳普湖县| 宜宾市| 颍上县| 通州市| 鄱阳县| 建昌县| 承德县|