Vive laser pointer turn off??
I have a scene where I am using SteamVR_LaserPointer.cs to pick an interactive object. Once the object is picked I am changing the scene. Just before I change scene I disable the SteamVR_LaserPointer.cs script.
But in the new scene the Laser Pointer is still there and visible on the Control and yet the Script for it is disabled.
Does anyone have any idea how I can turn this thing off??????? Thanks ....
Answer by mesadigitaldesign · Mar 01, 2019 at 05:14 PM
@diggerjohn greetings from the future! I just solved this one for myself in the SteamVR 2.2 package. It takes an alteration to the SteamVR_LaserPointer.cs script. In the Update() function, the first thing you see is this:
if(!isActive)
{
isActive = true;
this.transform.GetChild(0).gameObject.SetActive(true);
}
This seems to do nothing, and forces the laser to always be on. Also, the "active" public variable appears to do nothing. Period. Instead, replace that isActive section to this:
if(active != isActive)
{
isActive = active;
pointer?.SetActive(isActive);
}
if(!isActive)
return;
This allows you to actually turn the laser on/off by setting the public variable "active" to true or false. Alter to taste if you need other functionality to still be active when the visible laser is off.
Hey I realize I'm asking a question under a question here but none of the questions on this issue on Unity forums or S$$anonymous$$m forums are answered. How can you "click" an object using the Laser Pointer? I have a script on an object that does various things. I want to point the laser at the object, click my trigger button, and have the object read the clickdata by implementing the OnPointerClick(PointerEventData e) or OnPointerUp(PointerEventData e). Currently nothing happens when I do this
I don't have my codebase with me right now, but I'll try to get you headed in the right direction. I solve it by slightly changing the perspective. Use a Raycast to look for an object, then tell the object that it was clicked.
There is a raycast going on inside the laser pointer code, but I didn't want to have my operational code inside a third-party script that still needs updates, so I wrote my own simplified input handler script that just does its own raycast from the appropriate hand transform when the trigger click is called. Here's the link to manual on doing that: https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
Then you need to have a monobehavior on the object to react to being clicked. example, "$$anonymous$$yClass" with a function "Clicked". After doing the raycast and getting the "hit" variable, find that monobehavior object and activate it with this:
$$anonymous$$yClass thing = hit.collider.GetComponent<$$anonymous$$yClass>();
thing?.Cilcked(); // if it found one, call the function
Answer by diggerjohn · Mar 23, 2019 at 01:22 PM
Hey guys thanks for tracking this. I am happy to say I SOLVED this little problem. I migrated to VRTK. It's solid. No worries about Steam updates braking my code any more. Strongly recommend it.
Your answer
Follow this Question
Related Questions
How to "click" an object using SteamVR Laser Pointer 0 Answers
OnPointerEnter 0 Answers
Making a laser pointer (reflection included) 0 Answers
How to make a laser pointer with WebXR 0 Answers