I’m trying to access a public variable from another script and I’m getting a NullreferenceException.
I’ve searched for and read many of the 150+ pages on the issue and I think I can get around it with a “FInd” but I’m having a hard time with the syntax…I can’t find any examples that are on point with the syntax I need.
Here’s the Variables I want to access:
public class GameVars : MonoBehaviour
{
public int RedStrength;
public int BlueStrength;
}
BUT…when I try to access them from another script I get the null reference error.
Here is one example of the “Find” I’ve tried in another script…and I’ve tried different combination/variations of syntax from LOTS of “answers” but none seem to be what I need.
void Awake()
{
GameObject go = GameObject.Find ("BlueStrength");
go.GetComponent<GameVars> ().BlueStrength;
}
ODDLY…I was able to access this variable from the other script for awhile (without using any sort of “find”) but then I must have changed something that triggered the Null Exception error and now even though I’ve tried to replicate the problem free code I still get the error.
Thanks in advance for any help.