我现在很难从另一个脚本获取我的枚举值,这是我处理枚举的脚本
TrafficLightHandler.cs
public enum TRAFFIC_LIGHT{ 绿色, 黄色, …
为了能够使用其他脚本,您需要将其作为任何其他组件使用来检索 GetComponent<TCompoenent>() 。
GetComponent<TCompoenent>()
如果两个脚本都附加到同一个脚本 gameObject 然后只使用当前 gameObject
gameObject
var tlh = gameObject.GetComponent<TrafficLightHandler>(); ... tlh.Trafficlight
否则,如果脚本附加到不同的对象,则需要引用该脚本的持有者以进行实际检索。
public GameObject otherScriptHolder; var tlh = otherScriptHolder.GetComponent<TrafficLightHandler>(); ... tlh.Trafficlight