- Home /
interactable laser pointer with UI elements
Hi Im working on the project in VR and i have a problem. In my scene i have these items: camera rig Ui with button i attach this script to my right controller:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class pointer : MonoBehaviour { public float m_DefaultLength = 5.0f; public GameObject m_Dot; public VRInputModule m_InputModule; private LineRenderer m_LineRenderer = null; private void Awake() { m_LineRenderer = GetComponent(); } void Start() {
}
void Update()
{
UpdateLine();
}
private void UpdateLine()
{
// Use default or distance
float targetLength = m_DefaultLength;
// Raycast
RaycastHit hit = CreateRaycast(targetLength);
// Default
Vector3 endPosition = transform.position + (transform.forward * targetLength);
// Or based on hit
if (hit.collider != null)
endPosition = hit.point;
// Set position of the dot
m_Dot.transform.position = endPosition;
// Set linerenderer
m_LineRenderer.SetPosition(0, transform.position);
m_LineRenderer.SetPosition(1, endPosition);
}
private RaycastHit CreateRaycast(float length)
{
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
Physics.Raycast(ray, out hit, m_DefaultLength);
return hit;
}
}
and also a camera(with some change and its deactived) and line render. and attach a box collider on my button.
but the button cant detect the laser pointer.
what should i do?I watched all videos in youtube. please tell me the correct way to do. thanks
Your answer
Follow this Question
Related Questions
UI canvas attached to vive controller disappears after first run in editor on vive 0 Answers
Strange UI Button hover offset when using Worldspace Canvas in VR 4 Answers
How to display 3D object on top of UI World Space Canvas in VR 0 Answers
IPointerEnterHandler doesn't work when object switches parent 1 Answer
How do i move the slider with GVR reticle pointer? 0 Answers