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

 

转载于:https://www.cnblogs.com/C-9925/p/7350278.html

已标记关键词 清除标记
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页