I’m trying to call the function spawnWreckage() from a script called Ground.cs inside a unique object in my Scene, called Ground, with the following line of code:
transform.Find("Ground").GetComponent<Ground>().spawnWreckage((int)(distTraveled / 5));
But I get the dreaded
NullReferenceException: Object reference not set to an instance of an object
for some reason.
I have verified that I have a Ground object and that it has the desired Ground script. What gives?
NOTE: When I split that line up into more manageable sections, it always crashes at the GetComponent() stage, which is why I titled this post as it is.
On a side note, does anyone have any tips for naming here. Ground representing both a named game object and a script component is far from ideal, but what's the best approach?
– sosh