Skip to content

Instantly share code, notes, and snippets.

@AlexMeesters
Created June 30, 2019 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexMeesters/d87f07030cc13375c7a519b5aaa34117 to your computer and use it in GitHub Desktop.
Save AlexMeesters/d87f07030cc13375c7a519b5aaa34117 to your computer and use it in GitHub Desktop.
Simple movement tutorial
using UnityEngine;
public class MoveObject : MonoBehaviour
{
void Start()
{
// Changes the position to x:1, y:1, z:0
transform.position = new Vector3(1, 1, 0);
// It is also possible to set the position with a Vector2
// This automatically sets the Z axis to 0
transform.position = new Vector2(1, 1);
// Moving object on a single axis
Vector3 newPosition = transform.position; // We store the current position
newPosition.y = 100; // We set a axis, in this case the y axis
transform.position = newPosition; // We pass it back
}
private void Update()
{
// We add +1 to the x axis every frame.
// Time.deltaTime is the time it took to complete the last frame
// The result of this is that the object moves one unit on the x axis every second
transform.position += new Vector3(1 * Time.deltaTime, 0, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment