Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Line renderer won't show despite being enabled.

Discussion in 'Scripting' started by JBEDUnity, Jul 30, 2020.

  1. JBEDUnity

    JBEDUnity

    Joined:
    Jul 13, 2020
    Posts:
    23
    I'm trying to have a line show from the hand out as a ray whenever the index trigger is pressed. What I get is if I turn this script off the line shows up just fine. If I turn it on, I can get the debug to show the button was pressed but the line doesn't show up. I'm at a loss as to why the line renderer is perpetually disabled.

    Code (CSharp):
    1. using Oculus.Platform.Models;
    2. using Pixyz.Utils;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6.  
    7. public class Measure : MonoBehaviour
    8. {
    9.     //set up rays to represent hand to measurement point and point to point
    10.     public LineRenderer lrMeasure2;  //Ray from hand to point of measurement
    11.     //public LineRenderer Ray;    //Line showing point 1 to point 2
    12.  
    13.     //turn line on/off
    14.     private bool blLineActive =false;
    15.  
    16.     //get right hand position
    17.     public Transform trfmRightHand;
    18.  
    19.     // store input from right hand trigger
    20.     private float flHandRight = OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger);
    21.  
    22.     // Start is called before the first frame update
    23.     void Start()
    24.     {
    25.         //Set up line render
    26.         Vector3[] v3StartLinePosition = new Vector3[2] { Vector3.zero, Vector3.zero };
    27.         lrMeasure2.SetPositions(v3StartLinePosition);
    28.         lrMeasure2.enabled = false;
    29.     }
    30.  
    31.     // Update is called once per frame
    32.     void Update()
    33.     {
    34.         //string strTemp;
    35.  
    36.         //Run routine if right trigger button is pressed
    37.       flHandRight = OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger);
    38.  
    39.         if (flHandRight > 0.9)
    40.         {
    41.             blLineActive = true;
    42.             lrMeasure2.enabled = true;
    43.             Debug.Log("Right Trigger Pressed");
    44.             RaycastMeasure();
    45.  
    46.         } else
    47.         {
    48.             lrMeasure2.enabled = false;
    49.             blLineActive = false;          
    50.         }
    51.         if (blLineActive)
    52.         {
    53.             //get point data
    54.             RaycastMeasure();
    55.         }
    56.     }
     
  2. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,058
    Both 2 points are vector3.zero. First point is the start point, second point is the end of the line. But since they are both zero they overlap.
    What happens if you use a Vector3.Forward as second point?
     
  3. JBEDUnity

    JBEDUnity

    Joined:
    Jul 13, 2020
    Posts:
    23
    Oh, thanks. That did the trick. One more question, I've got the size of the renderer at Z of 100. When I run, I get the line but it keeps reverting to a Z of 1. How can I set this?