Point and Click to move lesson

Hi there - in the point and click to move the player lesson there is one line of code (variable) that is still there that I don’t understand why. I // it out of my code and it still works, can you tell me if this is just something that should have been deleted but wasn’t?
It’s the first line, the Transform.target. After implementing the RaycastHit and everything this doesn’t seem to do anything?

[SerializeField] Transform target;

void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        MoveToCursor();
    }

    
}

private void MoveToCursor()
{
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    RaycastHit hit;
    bool hasHit = Physics.Raycast(ray, out hit);
    if (hasHit == true)
    {
        GetComponent<NavMeshAgent>().destination = hit.point;
    }
}

}

That’s correct. We only used the target as a focus to get the character moving to start. We no longer need it now that we’re raycasting for a location to walk to.

Privacy & Terms