I’m trying to make it so that when you press the left mouse button, the player’s camera moves to the object. The problem is that when you press the mouse, the camera does not have time to get closer to the object.
void Update()
{
if (Physics.Raycast(_camera.transform.position, _camera.transform.forward, out var hit, _distanceMax) && hit.transform.tag == "Dynamic")
{
if (Input.GetButtonDown("Fire1"))
{
Debug.Log("Ok");
_camera.transform.position = Vector3.MoveTowards(_camera.transform.position, hit.transform.position, speed * Time.deltaTime);
}
}
}