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;
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值