前几天开发一个VR项目,要求得一开始进去,所看到的的场景要显示在进去的视觉,所以就写了一个强制朝向的一段代码,大家可以参考。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
using UnityEngine; using UnityEngine.UI; public class VRCameraReset : MonoBehaviour { GameObject cameraEye; void Start () { cameraEye = null; } // Update is called once per frame void Update () { if(!cameraEye && transform.FindChild ("Camera (eye)")) { cameraEye = transform.FindChild ("Camera (eye)").gameObject; floatangleRota = transform.rotation.eulerAngles.y - cameraEye.transform.rotation.eulerAngles.y; transform.Rotate (0, angleRota, 0); transform.position -= new Vector3(cameraEye.transform.position.x - transform.position.x, 0, cameraEye.transform.position.z - transform.position.z); } } } |
同时我个人博客也有http://myselfdream.blog.51cto.com/9944020/1871814文章源自大腿Plus-https://www.zhaoshijun.com/archives/399
有不对的地方大家也可指出来,一起讨论,一起修改哈。文章源自大腿Plus-https://www.zhaoshijun.com/archives/399
可以跟我们站长联系,或者跟我联系文章源自大腿Plus-https://www.zhaoshijun.com/archives/399 文章源自大腿Plus-https://www.zhaoshijun.com/archives/399
我的微信
微信扫一扫
shijun_z
我的QQ
QQ扫一扫
846207670
评论