Seems to be a problem

Notice our update method

void Update()

    {

        bool isInRange = Vector3.Distance(transform.position, target.position) < weaponRange;

        if(target != null && !isInRange)

        {

            GetComponent<Mover>().MoveTo(target.position);

        } 

        else

        {

            GetComponent<Mover>().Stop();

        }  

    }

PLEASE notice how we check for a null target one line LATE!

something is just not feeling correct here.

We were careful to check that we had a target… two lectures later now we create a bool using a target that could be null!
I am confused please help me get it.

Why check for target != null… for the getcomponent but NOT for the bool???
Thanks
Oh yea I forgot to mention my player doesn’t even move now because of this target not being set.

Yes, this should be corrected in the next lecture (at least according to the history of the commits that correspond to the lectures).

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms