I am writing a script for camera panning, now everything is working except I get a null reference exception on this line:
} else if (mouseHit.collider.name == null)
this is the code in some more context, the script is not finished yet
private void FixedUpdate()
{
mouseRay = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (mouseRay, out mouseHit))
{
Debug.Log (mouseHit.collider.name);
camCol = "" + mouseHit.collider.name;
} else if (mouseHit.collider.name == null)
{
camCol = "";
}
if (camCol == "")
{
transform.Translate (0, 0, 0);
}
if (camCol == "leftCam")
{
transform.Translate (-0.1f * panSpeed, 0, 0);
}
I only ask questions here as a last resort, any help would be greatly appreciated! Also, am I correct in thinking that the output of mouseHit.collider.name is a string?