Why does this raycast code give me a NullReferenceException? The Error in the code is NullReferenceException Object reference not set to an instance of an object for if (hitxx.collider.tag "soldier") Please help! Thanks in advance void Update () Physics.Raycast (eyeenemy.transform.position, (eyeenemyfront.transform.position eyeenemy.transform.position) 20,out hitxx) Debug.DrawRay (eyeenemy.transform.position, (eyeenemyfront.transform.position eyeenemy.transform.position) 20,Color.green) if (hitxx.collider.tag "soldier") gameObject.transform.LookAt (soldier.transform.position) Debug.Log ("chuchu")