Hi,
I am trying to write a script that invokes an onClicked and onReleased Event when a specific object is clicked. In particular, when the player clicks a virtual calendar that I modeled (consider it a regular cube object for now) the onClicked Event is invoked and a function is called that changes the year shown on the calendar. Now setting up the year change and the laser pointers itself was not hard to do. but what I am struggling with is getting the input from the click.
I have added the SteamVR_Laserpointer object to my right and left controller of my SteamVR Player prefab. The laser pointers appear in GameMode and react when I press the trigger of the controller (Vive HTC).
What is left is the script that gets attached to the calendar that invokes the event when the calendar is clicked. This is the little bit that I have so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using Valve.VR.Extras;
public class Calendar : MonoBehaviour
{
public UnityEvent onClicked, onReleased;
private bool clicked;
GameObject calendar;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (!clicked)
CalendarClicked();
if (clicked)
CalendarReleased();
}
private void CalendarClicked()
{
clicked = true;
onClicked.Invoke();
}
private void CalendarReleased()
{
clicked = false;
onReleased.Invoke();
}
}
My issue is that I don’t know how to get the actual input of the click, a.k.a. the object that the laser pointer is colliding with, when it’s clicked. Somehow I cannot find anything in the SteamVR API documentation about the laser pointer either. Infact, I can’t find ANYTHING on the laser pointer documentation…
Does anyone know how I can get the laser pointers input? Thank you in advance!