NullReferenceException Error

Hi,

I am getting the error: NullReferenceException: Object reference not set to an instance of an object.
It occurs when I click on any 3D object while in Play.

if (Input.GetMouseButtonDown (0))
        {
            Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit)){
            Transform projectile = Instantiate(missile, new Vector3(0f,0.301f,1.158f), Quaternion.identity) as Transform;
            // turn the projectile to hit.point
            projectile.LookAt(hit.point);              //Error here

            // accelerate it
            projectile.rigidbody.velocity = projectile.forward * 10;                //and error here also
            }
        }

if it’s erroring both those lines, then its projectile that is null
check that missile exists and has a transform

Thank you, I realized missile was declared as a gameobject and not a transform…