I'm really not sure why I'm getting this error, it's a very short script and I can't find a single thing wrong with it. I get a new instance of this error every single frame. The code works fine though, which is even more baffling.
void Update () {
if (this.GetComponent<BaseStatFunctions>().isPicked == false)
{
this.transform.position = new Vector3(transform.position.x, transform.position.y, 0);
this.transform.eulerAngles = new Vector3(0, 0, transform.eulerAngles.z);
}
else if (this.GetComponent<BaseStatFunctions>().isPicked == true)
{
GameObject ship = GameObject.Find("Ship");
this.transform.rotation = ship.transform.rotation;
}
}
void Update () {
BaseStatFunctions myScript = GetComponent<BaseStatFunctions>();
if (myScript ) // Checks if your script is null
{
if ( !myScript.isPicked)
{
transform.position = new Vector3(transform.position.x, transform.position.y, 0);
transform.eulerAngles = new Vector3(0, 0, transform.eulerAngles.z);
}
else
{
GameObject ship = GameObject.Find("Ship");
if (ship) // Checks if your ship exits
transform.rotation = ship.transform.rotation;
else
print("ship does not exits");
}
}
else
print("Script does not exits");
}
The point its to check if the objects you're using exist.in this part the 2 objects would be:
1. the "GetComponent()"
If this was missing then you might have forgotten to attach this script to the SAME GameObject. if you're calling it from another game object you should use this: GameObject.Find( "name of the gameObject" ).GetComponent();
the "ship"
If this was missing then you dont have a game object named "Ship" in your scene.