Last active
August 29, 2015 14:16
-
-
Save shinriyo/bfd7c5db049b5905a91a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
// angleのスピードで、とあるオブジェクトの周りを回転するスクリプト | |
public class TargetRotation : MonoBehaviour | |
{ | |
// 変数 | |
// 一秒当たりの回転角度 | |
public float angle = 30f; | |
private Transform myTransform; | |
// 回転の中心をとるために使う変数 | |
private Vector3 targetPos; | |
// Use this for initialization | |
void Start () | |
{ | |
myTransform = transform | |
// targetに、"Sample"の名前のオブジェクトのコンポーネントを見つけてアクセスする | |
Transform target = GameObject.Find("Sample").transform; | |
// 変数targetPosにSampleの位置情報を取得 | |
targetPos = target.position; | |
// 自分の向きをターゲットの正面に向ける | |
// myTransform.LookAt(target); | |
// 自分をZ軸を中心に0~360でランダムに回転させる | |
myTransform.Rotate(new Vector3(0, 0, Random.Range(0,360)),Space.World); | |
} | |
void Update () | |
{ | |
// Sampleを中心に自分を現在の上方向に、毎秒angle分だけ回転する。 | |
Vector3 axis = myTransform.TransformDirection(Vector3.up); | |
myTransform.RotateAround(targetPos, axis ,angle * Time.deltaTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment