unity move one object to another code example

Example 1: unity how to move an object to another object

// 3D
transform.position = new Vector3(GameObject.Find("Object").transform.position.x, GameObject.Find("Object").transform.position.y, GameObject.Find("Object").transform.position.z);

// 2D
transform.position = new Vector2(GameObject.Find("Object").transform.position.x, GameObject.Find("Object").transform.position.y);

Example 2: how to make an object move towards another in unity

transform.position = Vector3.MoveTowards(transform.position, taretPos, Qiaternion.identiy)

Tags:

Misc Example