Unity3d讓某個物體一直正對着相機

//將如下代碼綁定到相機上
using UnityEngine;
using System.Collections;
 
public class LookatScipt : MonoBehaviour {
 
// Use this for initialization
void Start () {
 
}
 
// Update is called once per frame
void Update () {
float x = Input.GetAxis ("Horizontal");//旋轉相機
float y = Input.GetAxis ("Vertical");
gameObject.transform.RotateAround(gameObject.transform.position, Vector3.up, x);
gameObject.transform.RotateAround(gameObject.transform.position, Vector3.right, y);
 
GameObject cube = GameObject.Find("Cube");//要正對着相機的物體
cube.transform.RotateAround(gameObject.transform.position, Vector3.up, x);
cube.transform.RotateAround(gameObject.transform.position, Vector3.right, y);
}
}
相關文章
相關標籤/搜索