- Home /
Question by
LeoSaurusRex · Apr 20, 2016 at 04:51 AM ·
instantiatedestroyglitchchild objectlaser beam
how to make a Portal 2-esque laser beam "redirection" system?
hello! sooo i've made this beam laser using a raycast etc etc. you can block it's path with varied obstacles such as crates, it's pretty neat. so i thought it'd be cool to come up with a way to redirect it (like the using of laser-redirection cubes or whatever in portal2). i got my "laser reflectors" to instantiate the same laser prefab on collision... i just can't get it the children prefabs to go away after the reflector stops getting hit by the laser. does that make sense??? im thinking on using ontriggerexit... but thats as far as i can get with deleting instantiated children. anyway, thanks a lot! bonus: any idea why my laser beam is glitching? it goes on and off repeatedly very fast, here's the script:
using UnityEngine;
using System.Collections;
public class Beam_Length_controller : MonoBehaviour {
public RaycastHit hit;
public float length;
public int useLayer = 1 << 9;
void Update()
{
length = hit.distance;
Debug.DrawRay (transform.position, transform.forward, Color.green);
gameObject.transform.localScale =new Vector3 (1, 1, length);
if (Physics.Raycast (transform.position, transform.forward, out hit, useLayer))
{
if (hit.collider.gameObject.tag == "Player")
{
print ("meaw");
}
}
}
}
Comment