I’m working with a click to move script but do not want the player moving to a specific point but to the center of an object. I have a code that works perfectly for the click to move but there is one small part where instead of a point I can’t seem to get the point to become a transform.
Here’s my script
public class Click2Move : MonoBehaviour
{
NavMeshAgent navAgent;
void Start ()
{
navAgent = GetComponent();
}
void Update ()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(ray, out hit))
{
navAgent.SetDestination(hit.point);
}
}
}
}
at the very end, the SetDestination(hit.point) is where I need to change the script. I’ve tried just changing the point to transform but it doesn’t seem to work. There is another step that I seem to be missing, can anyone help?