Unity框架:JKFrame2.0学习笔记(五)——事件系统(2)

阅读 77

2023-04-18

前言

上一篇记录了框架的事件系统的内部构成和实现,这篇记录下事件系统的使用。

如何使用

新建脚本EventTest

using JKFrame;
using UnityEngine;

public class EventTest : MonoBehaviour
{
    
    void Start()
    {
        //添加监听
       EventSystem.AddEventListener("inputC",InputKey); 
    }
    
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.C))
        {
            //触发事件
            EventSystem.EventTrigger("inputC");
        }
    }

    public void InputKey()
    {
        Debug.Log("按下了c键");
    }
}

脚本挂载到场景中,运行执行

Unity框架:JKFrame2.0学习笔记(五)——事件系统(2)_unity


精彩评论(0)

0 0 举报