on gameobject move unity code example
Example 1: unity how to move a gameobject towards another gameobject
// the script has been edited a little but is still very similar to the original post
public float speed;
public GameObject object1; // The game object that moves.
public GameObject object2; // the game object that Object 1 moves to.
void FixedUpdate()
{
// Calculate direction vector.
Vector3 dirction = object1.transform.position - object2.transform.position;
// Normalize resultant vector to unit Vector.
dirction = -dirction.normalized;
// Move in the direction of the direction vector every frame.
object1.transform.position += dirction * Time.deltaTime * speed;
}
Example 2: unity how to move an object
float x = 10f; //the x value for the object's position
float y = 10f; //the y value for the object's position
float z = 10f; //the z value for the object's position
Vector3 position = new Vector3(x, y, z); // this will create a vector with the values of the x, y, and z values
transform.position = position; //this change the object that this script is attached to position to the position vector that was created