Question by
Volatile_Potato · Aug 25, 2016 at 01:43 PM ·
vrraycasting
Vive highlight button by looking and select using controllers trigger.
Hi all,
What is the best way to do this? The intention is to highlight gameobjects by looking at it with the headset and GUI buttons and hit trigger to select.
Sending out a raycast from the headset's camera? Any ideas?
Comment
Answer by Volatile_Potato · Aug 26, 2016 at 12:40 PM
To highlight UI buttons makes sure the highlight option in the inspector is not white. Although this doesn't centre on straiht its just a tad top right.
I have not got to the select highlighted button or gameobject yet with right trigger still getting my head around Vive controller etc. -__-
Camera camera;
// Use this for initialization
void Start () {
camera = GetComponent<Camera> ();
}
// Update is called once per frame
void Update () {
Ray ray = camera.ViewportPointToRay(new Vector3(0.0F, 0.0F, 0));
RaycastHit hit;
}
}
For GameObjects I used shaders the code goes like this:
Camera camera;
private int currentColor,length;
public Renderer rend;
public bool isHighlighted = false;
public Shader unlitShader;
public Shader litShader;
// Use this for initialization
void Start () {
camera = GetComponent<Camera> ();
}
// Update is called once per frame
void Update () {
Ray ray = camera.ViewportPointToRay(new Vector3(0.0F, 0.0F, 0));
RaycastHit hit;
if (Physics.Raycast (ray, out hit)) {
if (!isHighlighted) {
rend.material.shader = litShader;
} else {
rend.material.shader = unlitShader;
}
}
}
}