vr现在已经很火热了,目前也出现了许多虚拟现实眼睛,比如 Htc Vive 、Oculus 、 Gear VR、 大朋 等等,他们都自带了unity开发的包,htc 、oculus都自带了人物控制移动的脚本,但是大朋却没有,现在就是让大家自己写出大朋的控制移动脚本,如下:
新建一个C#脚本,命名为:ChildTransform.cs
内容如下:
using UnityEngine;
using System.Collections;
public class ChildTransform : MonoBehaviour {
public Transform same;//眼睛
// Update is called once per frame
void FixedUpdate () {
transform.localEulerAngles = new Vector3(0, same.localEulerAngles.y+30f, 0);//获取眼睛Y轴旋转的角度
}
}
在新建一个空的GameObject,命名为MoveDic,将ChildTransform.cs赋予它
在新建一个脚本,命名为:Move.cs
内容如下:
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
[RequireComponent(typeof(CharacterController))]
public class Move : MonoBehaviour {
public Transform player;//需要移动的角色
public Transform dic;//方向,也就是MoveDic 那个空物体
private float speed=15;//移动速度
private CharacterController cc;//移动控制器
void Start() {
cc = this.GetComponent();
}
// Update is called once per frame
void FixedUpdate () {
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
cc.SimpleMove(h * dic.forward * 8);
cc.SimpleMove(-v * dic.right * speed);
}
}
这样就好了,可以插上自己的大朋眼睛,试试移动看看了!!!