LoginSignup
5
6

More than 5 years have passed since last update.

Unityである点を向けさせながら回転させる

Posted at

下記、ソースコードを対象のゲームオブジェクトにアタッチするとシーンの中心(0,0,0)をみながら

using UnityEngine;
using System.Collections;

public class MyCamera : MonoBehaviour {
    private Transform myTransform;

    void Awake ()
    {
        myTransform = transform;
    }

    void Update ()
    {
        Vector3 relativePos = Vector3.zero - myTransform.position;
        Quaternion rotation = Quaternion.LookRotation(relativePos);
        myTransform.rotation = rotation;
        myTransform.RotateAround (
                    Vector3.zero, Vector3.up,
                    10.0f * Time.deltaTime
                 );
    }
}
5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6