首页 > 编程语言 > 详细

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

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

 

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!