Unity Transform Essentials - 02 - transform.position property
Translating game objects using transform.position property:
Translating means changing position of a game object
transform.position:
- stores the position of a game object relative to the world coordinate system (or world origin) in the form of Vector3 structure
- is used to get or set position of a game object and move a game object relative to the world coordinate system (or world origin)
Example Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CubeController : MonoBehaviour {
// Use this for initialization
void Start () {
/*
Debug.Log (this.transform.position.x);
Debug.Log (this.transform.position.y);
Debug.Log (this.transform.position.z);
this.transform.position.x = 10f;
this.transform.position.y = 0f;
this.transform.position.z = 0f;
*/
//this.transform.position = new Vector3 (10f,0f,0f);
//this.transform.position = this.transform.position + new Vector3 (0f, 0f, 10f); // 0,0,10
//this.transform.position = this.transform.position + new Vector3 (0f, 0f, 10f); // 0,0,20
}
// Update is called once per frame
void Update () {
//this.transform.position = this.transform.position + new Vector3 (-10f, 0f, 0f) * Time.deltaTime;
this.transform.position += new Vector3 (-10f, 0f, 0f) * Time.deltaTime;
}
}
===================================
Follow the link for next video:
Unity Transform Essentials - 03 - transform.localPosition property
https://youtu.be/ur2ksHAw9SM
Follow the link for previous video:
Unity Transform Essentials - 01 - Transform Class Introduction
https://youtu.be/UST0SwYGwjs
===================================