Hi Guys,
I use Unity 2018.3.4f1, SteamVR: 2.2.0 and I have a HTC Vive. I’m struggling, because there are so many outdated tutorials and nothing that would work for my setup. Anyway, I think this tutorial could actually help me regarding interacting with the Canvas:
Unfortunately I get an error and I don’t know how to fix it or work around. I really could use some help here - do you have any suggestions?
This ist my code (detected error in red):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pointer : MonoBehaviour
{
public float m_DefaultLength = 5.0f;
public GameObject m_Dot;
public LaraVRImportModule m_InputModule;
private LineRenderer m_LineRenderer = null;
private void Awake()
{
m_LineRenderer = GetComponent();
}
private void Update()
{
UpdateLine();
}
private void UpdateLine()
{
// Use default or distance
float targetLength = m_DefaultLength;
// Raycast
RaycastHit hit = CreateRaycast(targetLength);
// Default End (if we don’t hit anything where is the dot?!)
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); //second position
}
private RaycastHit CreateRaycast(float length)
{
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
Physics.Raycast(ray, out hit, m_DefaultLength);
return hit;
}
}