一、瞬移功能
瞬移功能网上的例子挺多的,我就不多赘述了,在此附上一个例子,按着做就能实现瞬移:https://blog.csdn.net/Czhenya/article/details/78483099。
这里有一个地方需要说明一下,从商店里下载steamvr插件之后在导入瞬移插件,在瞬移插件脚本里会报错,是缺少命名空间的引用,没有过多的研究,我的方法是不要导入unity商店里的steamvr插件,直接导入瞬移插件即可。点击下载插件。
二、自由移动
这个功能也挺简单,这个功能是接着上一篇文章写的,如果看不懂就看一下我的上一篇文章,挺简单的直接上代码。把这个类直接放在Player上就可以。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class SLQPlayerController : MonoBehaviour {
//头
public Transform head = null;
//头的父节点
public Transform headRoot = null;
private NavMeshAgent navMeshAgent = null;
// Use this for initialization
void Start () {
navMeshAgent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update () {
// print(hand.forward);
//可以一直向着眼镜看的方向移动
transform.rotation = Quaternion.Euler(0, head.transform.rotation.eulerAngles.y, 0);
}
private void OnEnable()
{
SLQHandGripController.SLQTouchDataEvent += SLQHandGripController_SLQTouchDataEvent;
}
private void OnDisable()
{
SLQHandGripController.SLQTouchDataEvent -= SLQHandGripController_SLQTouchDataEvent;
}
private void SLQHandGripController_SLQTouchDataEvent(Vector2 _vec2)
{
//自由移动
//if (_vec2.x > -0.5f && _vec2.x < 0.5f && _vec2.y > 0.5f)
//{
// navMeshAgent.SetDestination(transform.position+transform.forward);
// handRoot.position = transform.position + transform.up;
//}
}
}