- Home /
How to access the light component on a camera object?
I have my scene set up with a camera called Main Camera. Attached is a Light component set to a spotlight and the camera is within an FPS controller. This is perfect because it lets the FPS controller handle the flashlight rotation automatically.
What I'm trying to do is toggle the intensity of the light with code based on whether the player has collected the flashlight object in-game or not (toggle on/off).
I'm having trouble figuring out how to access the light component of the camera.
Any help would be appreciated! Our team is working in Javascript for this project. :)
Answer by whydoidoit · Sep 28, 2013 at 08:11 AM
So if it is "on" the main camera then:
Camera.main.light.enabled = true;
If it is on the camera or in the child chain of the main camera:
Camera.main.GetComponentInChildren(Light).enabled = true;
Sorry, as you can probably tell I am pretty new to Unity. The light is part of the FPS $$anonymous$$ain Camera, it's a component added onto it. So I think it would be the Camera.main.GetComponent one?
I will try it out! :) Thank you.
Your answer
Follow this Question
Related Questions
Destroy object question! 3 Answers
Pan Orthographic Camera 0 Answers
How can i acces a component belonging to one gameObject from a second gameObject?-in Javascript 2 Answers
Set Max Rotation On Weapon Sway 0 Answers
Camera switch after specific time 1 Answer