This is probably a bit of a newbie question, but I'm new to C# and the whole prefabs thing.
I want to change a variable of an instantiated prefab from within another script. I know that I can do this with a GameObject that is already in the hierarchy, but how do I do this with an instance of a prefab. Here's what I am trying:
private ShipScript ship;
// Use this for initialization
void Start ()
{
ship = (ShipScript)GameObject.Find("ShipUnityPrefab").GetComponent("ShipScript");
}
.....
void doSomething ()
{
ship.variableA = 2;
}
It gives me a "NULLReferenceException Object reference not set to an instance of an object" error. The ShipUnityPrefab is instantiated just fine, I just can't seem to access it.
Thanks! -JJ