using UnityEngine;
using System.Collections;
public class VRFixedTeleport : MonoBehaviour {
private LineRenderer line;
private RaycastHit hit;
private SteamVR_TrackedObject trackedObject;
private SteamVR_Controller.Device device;
//Vector3[] poss;
// Use this for initialization
void Start () {
line = GetComponent<LineRenderer>();
trackedObject = GetComponent<SteamVR_TrackedObject>();
}
// Update is called once per frame
void Update () {
if (device == null)
device = SteamVR_Controller.Input((int)trackedObject.index);
TeleportWithRay(SteamVR_Controller.ButtonMask.Trigger, "chuan", "Texture_02259", "Texture_02258");
}
void TeleportWithRay(ulong whichKey,string tag,string resourcesPathOne,string resourcesPathTwo)
{
line.SetPosition(0, transform.position);
if (device.GetPress(whichKey) && Physics.Raycast(transform.position, transform.forward, out hit, 100))
{
line.SetPosition(1, hit.point);
line.enabled = true;
if (hit.collider.tag == tag)
{
line.material = Resources.Load(resourcesPathOne) as Material;
}
else
{
line.material = Resources.Load(resourcesPathTwo) as Material;
}
}
else
line.enabled = false;
if(device.GetPressUp(whichKey) && Physics.Raycast(transform.position, transform.forward, out hit, 10))
{
if (hit.collider.tag == tag)
{
Blink(2);
transform.parent.position = hit.transform.position;
}
}
}
//VR角色的Camare(eye)必须挂脚本SteamVR_Fade
private float fadeInTime = 0f;
protected virtual void Blink(float transitionSpeed)
{
fadeInTime = transitionSpeed;
SteamVR_Fade.Start(Color.black, 0);
Invoke("ReleaseBlink", 0);
}
private void ReleaseBlink()
{
SteamVR_Fade.Start(Color.clear, fadeInTime);
fadeInTime = 0f;
}
}
unity vr位移
最新推荐文章于 2024-01-15 17:05:05 发布