Unity中开发VR或者AR应用中我们想要物体和相机跟随着进行移动,我们需要先获得相机的参数,其次我们需要修改物体的参数使得其跟随移动 文章来源:https://www.toymoban.com/news/detail-571727.html
public class TestCubeStability : MonoBehaviour
{
public GameObject mainCamera;
// Start is called before the first frame update
void Start()
{
mainCamera = GameObject.Find("Main Camera");
}
// Update is called once per frame
void Update()
{
Vector3 Cam_Pos = mainCamera.transform.position;
Vector3 Cam_forward = mainCamera.transform.forward;
Vector3 Cam_right = mainCamera.transform.right;
Vector3 Cam_up = mainCamera.transform.up.normalized;
Vector3 OffSet = new Vector3(0, 1, 0);
Debug.Log(Cam_Pos);
this.transform.rotation = mainCamera.transform.rotation;
this.transform.position = Cam_Pos + Cam_forward;
}
}
使用this指针可以显示的改变本脚本下物体的参数,别忘了将该脚本挂载到物体下,就可以自动执行了文章来源地址https://www.toymoban.com/news/detail-571727.html
到了这里,关于Unity中如何让物体和相机一起动的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!