前几天开发一个VR项目,要求得一开始进去,所看到的的场景要显示在进去的视觉,所以就写了一个强制朝向的一段代码,大家可以参考。文章源自大腿Plus-https://www.shijunzh.com/archives/399
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.shijunzh.com/archives/399
有不对的地方大家也可指出来,一起讨论,一起修改哈。文章源自大腿Plus-https://www.shijunzh.com/archives/399
可以跟我们站长联系,或者跟我联系文章源自大腿Plus-https://www.shijunzh.com/archives/399
评论