I have a script that makes 4 different game object appear when the player looks in a certain direction, but I’m getting a strange error. Here’s the script…
var player : GameObject;
var north : GameObject;
var south : GameObject;
var east : GameObject;
var west : GameObject;
var yRotation : float = 5.0;
function Update () {
yRotation += Input.GetAxis("Horizontal");
if(player.transform.eulerAngles.y <= 45 && player.transform.eulerAngles.y > 315)
{
north.SetActive (true);
south.SetActive (false);
east.SetActive (false);
west.SetActive (false);
}
if(player.transform.eulerAngles.y <= 315 && player.transform.eularAngles.y > 225)
{
north.SetActive (false);
south.SetActive (false);
east.SetActive (false);
west.SetActive (true);
}
if(player.transform.eulerAngles.y <= 225 && player.transform.eulerAngles.y > 135)
{
north.SetActive (false);
south.SetActive (true);
east.SetActive (false);
west.SetActive (false);
}
if(player.transform.eulerAngles.y <= 135 && player.transform.eulerAngles.y > 45)
{
north.SetActive (false);
south.SetActive (false);
east.SetActive (true);
west.SetActive (false);
}
}
But I get this odd error. Even stranger is that it’s only on line 20, even though there are a few lines that have nearly the same thing. Here’s the error…
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[ ] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[ ] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name)
UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name)
Compass.Update () (at Assets/Compass.js:20)
What can I do?