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);
}
}

 

posted @ 2017-08-12 14:52  孔琳桂  阅读(2931)  评论(1编辑  收藏  举报