- Home /
SteamVR: How can I use SteamVRLaserPointer with Objects that are interactable( such as throwable)?
My code allows a map( a rectangle with covered with a map) to be highlighted using a laser pointer but if I add a rigidbody to this item which is required for an item to be throwable my laser pointer stops working any ideas on how to solve this problem will be appreciated.
This my working code:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using Valve.VR.Extras;
public class ViewMapSceneHandler : MonoBehaviour{
public SteamVR_LaserPointer laserPointer;
bool enabled = false;
public GameObject text;
//public GameObject ChildGameObject1;
void Awake()
{
laserPointer.PointerIn += PointerInside;
laserPointer.PointerOut += PointerOutside;
laserPointer.PointerClick += PointerClick;
text = GameObject.Find("railroadmap/viewmap");
}
public void PointerClick(object sender, PointerEventArgs e)
{
if (e.target.name == this.gameObject.name)
{
Debug.Log("Cube was clicked");
}
}
public void PointerInside(object sender, PointerEventArgs e)
{
if (e.target.name == this.gameObject.name )
{
Debug.Log("Cube was entered");
if(enabled == false){
enabled = true;
text.GetComponent<MeshRenderer>().enabled = true;
}
}
}
public void PointerOutside(object sender, PointerEventArgs e)
{
if (e.target.name == this.gameObject.name )
{
Debug.Log("Cube was exited");
if(enabled == true){
enabled = false;
text.GetComponent<MeshRenderer>().enabled = false;
}
}
}
}
Your answer
Follow this Question
Related Questions
How to stop seeing through a wall in VR? 0 Answers
[SteamVR Mixed Reality] Quadratic View Only Show Black Screen 2 Answers
Getting started with VR (Vive) and unity 5.5.0 0 Answers
How to implement SteamVR Laser Pointer 2 Answers
Getting button input from Oculus Rift controller with Steam VR 0 Answers