transformコンポーネントのRotateを変更することで、オブジェクトを回転させる方法についての解説です。
成果物

Rotateを変更し、オブジェクトを回転させてみます。
transform.Rotateの使い方
オブジェクトを回転させる
オブジェクト.transform.Rotate(x, y, z);
オブジェクト.transform.Rotate(x, y, z);

オブジェクトを回転させるには、transform.Rotateの後にx,y,zの順で回転度数を指定します。

2Dの場合、使用するのは最後のz軸のみです。数値を普通に打ち込むと、度数として扱われます。

というわけで、Updateにthis.transform.Rotate(0, 0, 180);と入力したスプリクトをアタッチすると、

こんな感じになります。これはちょっと激しいので、

UpdateやFixedUpdateの場合は、もうちょっと小さい数値を入力するとアニメーションっぽくなります。今度はthis.transform.Rotate(0, 0, 1);としてみます。

実行結果です。

this.transform.Rotate(0, 0, -1);で右回りにすることができます。

やりたいことから逆引きするUNITYの使い方まとめ
Unityをやりたいことから学習していけるよう、機能・用途別にまとめたページです。C#の命令別の逆引きは現時点で作っていません。2019の時期に書き始めているので、それより前のバージョンについては言及しません。
コメント