Created
December 9, 2017 23:37
-
-
Save ajmwagar/3c79c7d7e84a7d9f6e6990f781255195 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections.Generic; | |
public class Controls : MonoBehaviour { | |
// This | |
public RaycastHit lastRaycastHit; | |
public LayerMask teleportLayer; | |
public GameObject player; | |
public Camera cam; | |
// Controller | |
private SteamVR_TrackedObject trackedObj; | |
private SteamVR_Controller.Device Controller | |
{ | |
get { return SteamVR_Controller.Input((int)trackedObj.index); } | |
} | |
private GameObject GazePoint() | |
{ | |
Vector3 origin = this.player.transform.position; | |
Vector3 direction = this.cam.transform.forward; | |
float range = 200; | |
if (Physics.Raycast(origin, direction, out lastRaycastHit, range, teleportLayer.value)){ | |
return lastRaycastHit.collider.gameObject; | |
} | |
else { | |
return null; | |
} | |
} | |
void Awake() | |
{ | |
trackedObj = GetComponent<SteamVR_TrackedObject>(); | |
} | |
void Start (){ | |
} | |
void FixedUpdate () { | |
if (Controller.GetPressDown(SteamVR_Controller.ButtonMask.Axis1) || Controller.GetPressDown(SteamVR_Controller.ButtonMask.Axis0) || Controller.GetPressDown(SteamVR_Controller.ButtonMask.Axis3) || Controller.GetPressDown(SteamVR_Controller.ButtonMask.Axis4)) | |
{ | |
this.teleport(); | |
} | |
} | |
public void teleport () | |
{ | |
this.player.transform.position = lastRaycastHit.point + lastRaycastHit.normal * 2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment