I haven’t been able to find anything useful on this considering I don’t know how to look for it, but I was told to make a singleton for my code since I needed a variable that could be used on another script since the variable is being changed. But when I use it on another script it does not produce the same number since it is static. So basically the first code is:
public int itemNumber;
static public classname instance;
void Start()
{
itemNumber = Random.Range (0, 7)
}
And in the other script I try to use whatever number itemNumber generated by doing:
public int itemNumberTwo
SpinWheel.instance.itemNumber = temNumberTwo
But when I run the script it later does not result in the same numbers I’m guessing because it is static. I try to remove that part but then it says an object reference is needed to access the non-static field. Any ideas? Sorry if the way I tried to explain this doesn’t make sense don’t know a bit of C# mostly just java.
Well my first suggestion is that if someone told you to use a "singleton" when you ask on how yo access the var in another script i would suggest not taking into account that suggestions. For changing the var you just need a reference to that object using getcomponent for example if its a monobehaviour, and leave singletons for managers or try to avoid them. Static means that is associated to the class rather than to an object, if you dont want it to be static you need the object reference.
– xxmariofer