unity vr位移

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的图片处理操作
下一篇unity 串口编程
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭