- Home /
Destroy object after time Only if raycast is colliding;
 void Update()
 {
     _lr.enabled = false;
     _lr.SetPosition(0, transform.position);
     RaycastHit hit;
     if (Physics.Raycast(transform.position, -transform.forward, out hit))
     {
         if (hit.collider)
         {
             _lr.SetPosition(1, hit.point);
             if (hit.collider.tag == "Cube")
             {
                 _hitObject = hit.collider.gameObject;
             }
             else StopCoroutine(Destroy());
         }
     }
     else _lr.SetPosition(1, -transform.forward * 5000);
     if (SteamVR_Input._default.inActions.Squeeze.GetAxis(SteamVR_Input_Sources.Any) > 0.5f)
     {
         _lr.enabled = true;
         StartCoroutine(Destroy());
     }
 }
i want to stop the Coroutine 'Destroy' as soon as the raycast doesn't hit the object anymore.
               Comment
              
 
               
              I want to have like a $$anonymous$$ing laser as in No $$anonymous$$ans Sky for reference. So i want to be able to destroy something after 3 seconds. But i dont want it to be destroyed if i dont press the button anymore.
Your answer
 
 
             Follow this Question
Related Questions
Animation on Raycast Not Playing 1 Answer
First VR experiment: IndexOutOfRangeException: Array index is out of range. 2 Answers
Editor Crashes When Switching from VR to Standalone 0 Answers
SteamVR prefabs work in one project, but not another 1 Answer
Add mesh colliders to (any) SteamVR controllers (in unity) 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                