How to get enum values from another script (Unity)

后端 未结 1 976
无人共我
无人共我 2020-12-07 04:45

I\'m currently having a trouble of getting the value of my enum from another script here\'s my script that handles the enum

TrafficLightHandler.cs

相关标签:
1条回答
  • 2020-12-07 05:37

    To be able to use the other script you need to retrieve it as any other component using GetComponent<TCompoenent>().

    If both scripts are attached to the same gameObject then just use current gameObject

    var tlh = gameObject.GetComponent<TrafficLightHandler>();
    ...
    tlh.Trafficlight
    

    Otherwise, if scripts are attached to different object then you need the reference to the holder of that script to do actual retrieval.

    public GameObject otherScriptHolder;
    var tlh = otherScriptHolder.GetComponent<TrafficLightHandler>();
    ...
    tlh.Trafficlight
    
    0 讨论(0)
提交回复
热议问题