- Home /
When flashlight hits invisible object, make it appear?
Using C#, I would like to be able to use flashlights to make objects appear and disappear, but I don't know how. Currently I have two different types of lights which can be switched on/off by pressing certain keys.
This is basically what I want to happen: An object starts off invisible. When a certain flashlight's light (just call it flashlight1) hits this object, the object should appear, but at all other times, it should be invisible. I'm currently trying to test it using a tree (with a mesh renderer). Could someone please tell me how to code this? Yes, the script is attached to the flashlight already.
I am not sure if you have a test in Unity whether light is falling on a mesh or not. But you can do either of these:
1) Use Vector3.Angle. When the angle between the flashlight and the object is withing some range, then turn it visible
2) Use raycasts. When the raycast hits, turn it visible
Your answer