c# - how to get an enum from another script in unity -
i trying create win condition script pulling status of enum different script , stuff it.
crowd.cs public enum crowdoptions {none, teama, teamb}; public crowdoptions crowd; crowd = crowdoption.none;
i have crowd doing bunch of stuff, lets set none.
winning.cs if (crowd = crowdoption.none){ } else if (crowd = crowdoption.teama){ } else { }
i tried getcomponent , set result of of crowd newvariable, don't think did right
public crowdsway = gameobject.find("crowdmanager").getcomponent<crowdmanager>();
i tried
if (crowdmanager.crowd = crowdoptions.none) { print("none"); } else { print("hmmmmmm"); }
that didn't work either.
in order access crowd enum variable in crowd.cs class script, script needs have instance of crowd object. example:
public class crowd : monobehaviour { public enum crowdoptions {none, teama, teamb}; public crowdoptions crowdopts; } public class winning : monobehaviour { void start() { crowd mycrowd = new crowd(); if(mycrowd.crowdopts == crowdoptions.none) { //do } } }
alternatively, make crowdoptions enum variable static. can access script name.
public class crowd : monobehaviour { public enum crowdoptions {none, teama, teamb}; public static crowdoptions crowdoptions; } public class winning : monobehaviour { void start() { if(crowdoptions == crowd.crowdoptions.none) { //do } } }
Comments
Post a Comment