SteamVR按键的简单操作

using UnityEngine;
using System.Collections;

public class MyAK : MonoBehaviour {

    public Transform firePos;
    public GameObject fire;

    SteamVR_TrackedObject vrTobj;
    SteamVR_Controller.Device device;


	// Use this for initialization
	void Start () {

        vrTobj = GetComponent();
        device = SteamVR_Controller.Input((int)vrTobj.index);
	}
	
	// Update is called once per frame
	void Update () {
        if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) 
        {
            GameObject go = GameObject.Instantiate(fire) as GameObject;
            go.transform.position = firePos.position;
            go.transform.rotation = firePos.rotation;
            RaycastHit hit;
            if (Physics .Raycast (firePos .transform .position ,firePos .transform .forward ,out hit ))
            {
                Debug.DrawLine(firePos.transform.position, hit.point, Color.red);
                if (hit .collider !=null )
                {
                    Debug.Log(hit.collider.name);
                    
                }
                
            }
        }
	
    }
}

你可能感兴趣的:(SteamVR按键的简单操作)