Last active
August 2, 2019 22:13
-
-
Save Sarthakg91/da7798e24849fa9c4a6f1fb49e06e349 to your computer and use it in GitHub Desktop.
button press detection
This file contains hidden or 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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using Valve.VR; | |
public class BaseColliderControl : MonoBehaviour | |
{ | |
public GameObject rightController; | |
public GameObject leftController; | |
public SteamVR_Action_Vibration hapticAction; | |
public SteamVR_Input_Sources hand; | |
private bool waitOn; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
waitOn = false; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
IEnumerator waitForSecs(float f) | |
{ | |
waitOn = true; | |
yield return new WaitForSeconds(f); | |
waitOn = false; | |
} | |
private void OnTriggerEnter(Collider other) | |
{ | |
Debug.Log("Enterred collison" + other.name); | |
string object_name = other.name; | |
if (!waitOn && object_name.Contains("StartButton")) | |
{ | |
if (rightController.GetComponent<ControllerCollisonDetector>().IsColliding()) | |
hapticAction.Execute(0.0f, 0.1f, 50.0f, 0.2f, SteamVR_Input_Sources.RightHand); | |
else if (leftController.GetComponent<ControllerCollisonDetector>().IsColliding()) | |
hapticAction.Execute(0.0f, 0.1f, 50.0f, 0.2f, SteamVR_Input_Sources.LeftHand); | |
GameObject button_text = other.transform.Find("ButtonText").gameObject; | |
button_text.GetComponent<TextMesh>().color = Color.cyan; | |
waitForSecs(0.15f); | |
} | |
} | |
void OnTriggerExit(Collider other) | |
{ | |
string object_name = other.name; | |
if (!waitOn && object_name.Contains("StartButton")) | |
{ | |
if (rightController.GetComponent<ControllerCollisonDetector>().IsColliding()) | |
hapticAction.Execute(0.0f, 0.1f, 50.0f, 0.2f, SteamVR_Input_Sources.RightHand); | |
else if (leftController.GetComponent<ControllerCollisonDetector>().IsColliding()) | |
hapticAction.Execute(0.0f, 0.1f, 50.0f, 0.2f, SteamVR_Input_Sources.LeftHand); | |
GameObject button_text = other.transform.Find("ButtonText").gameObject; | |
button_text.GetComponent<TextMesh>().color = Color.white; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment