完成1.1 VRTK基础配置后再进行本步骤。
UI设置
新建UI等内容请点击 1.4 VRTK与UI交互 第一步 场景设计
跟随相机
- 点击Canvas添加脚本 FollowCamera
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowCamera : MonoBehaviour
{
public float a;
public float b;
public float c;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.rotation = Camera.main.transform.rotation;
transform.TransformDirection(Camera.main.transform.forward);
transform.position = Camera.main.transform.position;
transform.Translate(new Vector3(a,b,c));
}
}
- 回到Unity中,运行的同时,回到Scene面板中,点击Canvas,调整Inspector面板中FollowCamera脚本中的a/b/c数值,查看应放置的位置;本人使用的数值为:
可以根据自己情况进行调整。transform.Translate(new Vector3(0f, 0f, 3.25f));
如有错误,欢迎指正
本人CSDN链接:大嘴先生
本人邮箱:D_9876@163.com
如本文对您有帮助的话,麻烦点个赞