Hello everyone,
I am not that familiar with scripting, and need some guidance.
I have the following object (laser) that has a line-renderer as the actual laser (which by default, I will toggle off on the object).
What I’m trying to achieve is that once I have this object collide with my trigger on another game object, it enables the visiblity of the line renderer.
Thank you in advance!
Kind regards,
Kevin
Do you have any code?
OK you need to do an OnTriggerEnter on the game object you are colliding with. Go to your Unity Scripting API documentation and you’ll see a good explanation and example code.
So you will create a new script and put it on the “trigger” game object with an OnTriggerEnter like the example in the documentation.
To get it to work, in that script you will also need to create a public variable at the top of the script. public LineRenderer rend. Before you run the code, make sure you drag your lineReneder gameobject to that script. (no need to do anything else but that).
You don’t need the script you created, but you do need to copy the ToggleVisibility function - it will work with the rend variable you just created. So copy that whole function to your new script.
In your OnTriggerEnter, you will call ToggleVisibility
Pay close attention to the explanation in the documentation!