Like the title says, I’m at my absolute wit’s end. Going bonkers.
Sometimes, “function Start()” works, sometimes it seems not to. I have to assume I am doing something wrong, but for the life of me, I cannot figure it out. To make things worse, every time I THINK i’ve fixed it, the issue just randomly comes back…no logic to this. AHHG!
So, an example code goes thusly (attached to an “asteroid” object that is instantiated in by a spawner code):
function Start()
{
gameInfoScript = GameObject.FindWithTag("GameInfo").GetComponent(GameInfoScript);
if (randomizeAsteroid)
RandomizeAsteroid();
}
function RandomizeAsteroid()
{
asteroidSpeed = (asteroidBaseSpeed *gameInfoScript.asteroidSpeedMultiplier);
}
Now, I have a simple “cube” object in my scene, with the “GameInfoScript” attached. This script has the “asteroidSpeedMultiplier” variable, and the cube is tagged as “GameInfo”. Nothing wrong there, yes?
However, out of the frackin blue, Unity is suddenly saying “…Object reference null…”- and in the inspector, i see that suddenly this “asteroid” cannot find the “GameInfoScript”. So, I’ll restart unity a few times, erase-and rewrite the script a few times, NO changes- and suddenly it’s working happily again. NO changes to the script!
I just don’t get it…please…please can anyone help save my sanity??? Am I doing something wrong here? How can I eliminate this issue???
Thank you!