Vive controller input not working
I'm trying to put Vive controller input using the native unity input system and it is not registering any button presses on the Vive controllers. I'm using unity 2018.2.10f1 and have Steam VR in my project. The controllers are visible in play mode and I have a raycast script on them that is working to point at things, but I am not able to register any button presses.
The input settings I have in the project
The code where I'm using it
print(Input.GetButton("SelectObject")); //debug to see if I'm getting any input from Vive
if ((Input.GetMouseButtonDown(0) || Input.GetKeyDown("joystick button 0")) && affectedSphere.sphereHover && !affectedSphere.sphereHit)
My full script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ControllerRaycast : MonoBehaviour {
public string interactionItemTag = "SoundObject";
SoundObject affectedSphere;
bool sphereInteraction;
private void Start()
{
affectedSphere = FindObjectOfType<SoundObject>(); //used to prevent errors with no selected sound object
}
void Update () {
RaycastHit hit;
Ray pointerRay = new Ray(transform.position, transform.forward);
Debug.DrawRay(transform.position, transform.forward, Color.green);
print(Input.GetButton("SelectObject")); //debug to see if I'm getting any input from Vive
if ((Input.GetMouseButtonDown(0) || Input.GetKeyDown("joystick button 0")) && affectedSphere.sphereHover && !affectedSphere.sphereHit)
{
print("mouse click");
SphereActivate();
}
if (!sphereInteraction)
{
if (Physics.Raycast(pointerRay, out hit))
{
if (hit.collider.tag == interactionItemTag)
{
affectedSphere = hit.collider.GetComponent<SoundObject>();
if (!affectedSphere.sphereHit)
SphereHover();
}
}
}
else if (!affectedSphere.sphereHit)
{
if (Physics.Raycast(pointerRay, out hit))
{
if (hit.collider.tag != interactionItemTag)
{
SphereExit();
}
}
else
{
SphereExit();
}
}
}
void SphereHover()
{
affectedSphere.sphereHover = true;
sphereInteraction = true;
affectedSphere.ObjectHover();
}
void SphereExit()
{
affectedSphere.sphereHover = false;
sphereInteraction = false;
affectedSphere.ObjectExit();
}
void SphereActivate()
{
affectedSphere.sphereHit = true;
sphereInteraction = false;
affectedSphere.ObjectActivate();
}
void SphereDeactivate()
{
affectedSphere.sphereHit = false;
affectedSphere.ObjectDeactivate();
}
}
Answer by cisin · Feb 01, 2019 at 04:16 PM
1. using System.Collections;
2. using System.Collections.Generic;
3. using UnityEngine;
4.
5. public class ControllerRaycast : MonoBehaviour {
6.
7. public string interactionItemTag = "SoundObject";
8.
9. SoundObject affectedSphere;
10. bool sphereInteraction;
11.
12. private void Start()
13. {
14. affectedSphere = FindObjectOfType<SoundObject>(); //used to prevent errors with no selected sound object
15. }
16.
17. void Update () {
18. RaycastHit hit;
19. Ray pointerRay = new Ray(transform.position, transform.forward);
20. Debug.DrawRay(transform.position, transform.forward, Color.green);
21.
22.
23. // print(Input.GetButton("SelectObject")); //debug to see if I'm getting any input from Vive
24. if ((Input.GetMouseButtonDown(0) || Input.GetKeyDown("SelectObject")) && affectedSphere.sphereHover && !affectedSphere.sphereHit)
25. {
26. print("mouse click");
27. SphereActivate();
28. }
29. if (!sphereInteraction)
30. {
31. if (Physics.Raycast(pointerRay, out hit))
32. {
33. if (hit.collider.tag == interactionItemTag)
34. {
35. affectedSphere = hit.collider.GetComponent<SoundObject>();
36. if (!affectedSphere.sphereHit)
37. SphereHover();
38. }
39. }
40. }
41. else if (!affectedSphere.sphereHit)
42. {
43. if (Physics.Raycast(pointerRay, out hit))
44. {
45. if (hit.collider.tag != interactionItemTag)
46. {
47. SphereExit();
48. }
49. }
50. else
51. {
52. SphereExit();
53. }
54. }
55. }
56.
57. void SphereHover()
58. {
59. affectedSphere.sphereHover = true;
60. sphereInteraction = true;
61. affectedSphere.ObjectHover();
62. }
63.
64. void SphereExit()
65. {
66. affectedSphere.sphereHover = false;
67. sphereInteraction = false;
68. affectedSphere.ObjectExit();
69. }
70.
71. void SphereActivate()
72. {
73. affectedSphere.sphereHit = true;
74. sphereInteraction = false;
75. affectedSphere.ObjectActivate();
76. }
77.
78. void SphereDeactivate()
79. {
80. affectedSphere.sphereHit = false;
81. affectedSphere.ObjectDeactivate();
82. }
83. }
84.
85.
86.
Your answer
Follow this Question
Related Questions
Google Cardboard + GazeInputModule: Capture trigger when not activated over UI 0 Answers
How to disable Vive Controllers 5.5 support 1 Answer
Help me doing teleportation with oculus touch 1 Answer
Google Cardboard VR + GazeInputModule - Get trigger events when not over UI 1 Answer
Do I need to use the Input Manager to register all input axes? 0 Answers