<GameObjectのTransformインスタンス>.Translate(<動かす幅をまとめたVector3インスタンス>); (例) Translate(new Vector3(1, 2, 3));
public class myscript : MonoBehaviour { //このクラスで使う値をずっと保管しておくフィールド //フィールドに保管しておかないとUpdate終了時に消えてしまう int counter = 0; float plus = 0.1f; void Start () { } void Update () { Vector3 p = new Vector3 (0, 0, plus); transform.Translate (p); counter++; if (counter == 100) { counter = 0; plus *= -1; } } }
public class myscript : MonoBehaviour { float zvalue = 0f; int plusminus = 1; void Start () { } void Update () { zvalue += 0.1f * plusminus; Vector3 p = new Vector3 (0, 0, zvalue); transform.position = p; if (zvalue > 10) { plusminus = -1; } if (zvalue < 0) { plusminus = 1; } } }
<動かしたいGameObjectのTransformインスタンス>.Rotate (動かす角度をまとめたVector3インスタンス);
public class myscript : MonoBehaviour { void Start () { } void Update () { var v = new Vector3 (0.1f, 0.1f, 0.1f); transform.Rotate (v); } }