- Home /
Enabling disabling objects via raycast
At first i have bad english sorry for that. I have a Script called playerdetection which Fires a Raycast in front of my camera in the update method.The ray detects a specific layer which i setted up. So when my ray hits my cube at the triggercollider it enables the child object. My Cube has two scripts a cubemaster script and a cubeshow script.They are connected with events.I have a event which enables the child object. The playerdetectionscript has a private Transform variable.This variable gets filled if the raycast has the cube. So my raycast calls the event in the cubeshow script and my child object gets enabled. But i want it to disable if my ray not points to the cube. The ray gets called in a if statement an i tried it to disable in a else statement. The problem is that my scripts loses the reference to my cube object because its declared in the if statement like : detectedobject = hit.transform. Could someone help me with my code or has someone a better solution? im lost and im trying to make it dynamic with events. Btw Im coding in c#
Your answer
![](https://koobas.hobune.stream/wayback/20220612090232im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
My Build Platform won't change. 0 Answers
Help with managing your character with the camera 0 Answers
How would I make a character select screen? 0 Answers
Need help with script 1 Answer
How to include js libraries ,.css 0 Answers