So i want to make flashlight and i downloaded some model from internet and i attached spot light component to this model. Now i want to turn on and off this flashlight. I know i can simply make visible or invisible this light in editor but my player camera can see it whatever light is on or off. I dont have any idea
To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime. Doing this should help you answer these types of questions: - is this code even running? which parts are running? how often does it run? - what are the values of the variables involved? Are they initialized? Knowing this information will help you reason about the behavior you are seeing. How to report your problem productively in the Unity3D forums: http://plbm.com/?p=220 When you post code, please use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/
Try creating a script with a reference to the spot light component. Attach the script to somewhere that makes sense, like to the flashlight object, the player, etc. Drag the spot light component to the reference on the instance of the new script. In the script write your logic for turning on/off the light. How you actually turn it on and off in the script is just enabling/disabling the spot light component via the reference to it. That should activate/deactivate the light. If you run into trouble, try posting what you have for the script, and people can help further. As already mentioned, post code using CODE tags. See Kurt's link.