素人のUnity学習日記 その3
チュートリアルその2
玉転がしのチュートリアルです。
Home · unity3d-jp/FirstTutorial Wiki · GitHub
上記の玉転がしを参考に
ステージを傾けて玉を転がしゴールを目指す脱出ゲームを作成。
ステージを傾けるスクリプト。
void Update () { float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); float angle = 30; transform.rotation = Quaternion.AngleAxis(angle * horizontal, Vector3.back) * Quaternion.AngleAxis(angle * vertical, Vector3.right); }
傾くスピードが速いので遅く変更。
void Update () { float speed = 10f; float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); float angle = 30; float step = speed * Time.deltaTime; transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.AngleAxis(angle * horizontal, Vector3.back) * Quaternion.AngleAxis(angle * vertical, Vector3.right),step); }
unityroomにあげています
https://unityroom.com/games/meirohajimete