how to make a object point towards another object in unity code example
Example 1: how to make an object point towards the mouse in unity
//Inside your update loop, add the following code:
//First, get the mouse position
Vector2 mousePosition = new Vector2 (
Input.GetAxis("MouseX"),
Input.GetAxis("MouseY")
);
//Then, use unity's built-in lookAt function to do all the math for you:
transform.LookAt(mousePosition);
Example 2: how to make an object move towards another in unity
transform.position = Vector3.MoveTowards(transform.position, taretPos, Qiaternion.identiy)