Unity3d让某个物体一直正对着相机

时间:2017-08-12 15:01:57   收藏:0   阅读:683
//将以下代码绑定到相机上
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);
}
}

 

原文:http://www.cnblogs.com/C-9925/p/7350278.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!