Bad*_*Cat 0 events event-handling game-engine unity-game-engine
我正在编写一个 Unity 编辑器脚本,需要确保 (UI) 事件系统存在,所以我想创建一个,如果它不存在的话。但是在尝试将其导入脚本时无法找到EventSystem类和StandaloneInputModule类。这是怎么回事?我也找不到关于这个问题的任何其他信息。
是的,您可以EventSystem从脚本创建一个。与任何其他组件一样,创建一个GameObject并向其添加所需的组件。
using UnityEngine;
using UnityEngine.EventSystems;
public class CreateEventSystem : MonoBehaviour
{
void Start()
{
if (FindObjectOfType<EventSystem>() == null)
{
var eventSystem = new GameObject("EventSystem", typeof(EventSystem), typeof(StandaloneInputModule));
}
}
}
Run Code Online (Sandbox Code Playgroud)