今回は、オブジェクトを回転させる方法 について紹介していきます。
簡単に実装することができるので、もしよかったら試してみてください。
オブジェクトを回転させるスクリプト
using UnityEngine;
using System.Collections;
public class RotatesphereY5 : MonoBehaviour
{
void Update()
{
transform.Rotate(new Vector3(0, 5, 0));
}
}
上記のような スクリプトを作ります。
そのままコピペしてもらえればOKです。
実際にUnityエディターで確認
先ほど作ったRotatesphereY5.csを回転させたいオブジェクトにアタッチします。
ゲームスタートボタンを押して確認します。
画像なのでわかりずらいですが、Y軸を軸にして回転しています。
X軸、Y軸、Z軸で回転させたい場合のスクリプト
X軸、Y軸、Z軸、で回転させるスクリプトも公開しておきます。
using UnityEngine;
using System.Collections;
public class RotatesphereX5 : MonoBehaviour
{
void Update()
{
transform.Rotate(new Vector3(5, 0, 0));
}
}
X軸を軸に回転させたい場合のスクリプト。
using UnityEngine;
using System.Collections;
public class RotatesphereY5 : MonoBehaviour
{
void Update()
{
transform.Rotate(new Vector3(0, 5, 0));
}
}
Y軸を軸に回転させたい場合のスクリプト。
using UnityEngine;
using System.Collections;
public class RotatesphereZ5 : MonoBehaviour
{
void Update()
{
transform.Rotate(new Vector3(0, 0, 5));
}
}
Z軸を軸に回転させたい場合のスクリプト。
終わり。