Question by
DoomsDayFortress · May 17, 2019 at 08:05 AM ·
reflectionpointerlaser
Making a laser pointer (reflection included)
Hey everyone, for a school project I have to make a laser pointer which shoots out a laser and reflects with the surfaces it touches. Only, it doesn't reflect anything and I don't know why.
public class laserPointer : MonoBehaviour
{
private LineRenderer laser;
Ray ray;
RaycastHit hit;
// Start is called before the first frame update
void Start()
{
laser = GetComponent<LineRenderer>();
}
// Update is called once per frame
void Update()
{
Vector3 inDirection = ray.direction;
Vector3 reflectedDir = Vector3.Reflect(inDirection, hit.normal);
if (Physics.Raycast(transform.position, transform.forward, out hit))
{
if (hit.collider)
{
laser.SetPosition(1, new Vector3(0, 0, hit.distance));
}
}
else
{
laser.SetPosition(1, new Vector3(0, 0, 100));
}
}
}
This is the code I'm using right now and the laser does stop on the surfaces it touches but then it does nothing. Can anyone help?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612201520im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Making a laser pointer (reflection included) 0 Answers
Raycast Reflection 2D 1 Answer
How to "click" an object using SteamVR Laser Pointer 0 Answers
Vive laser pointer turn off?? 2 Answers