- Home /
light on collision help (scripting)
i want a light to be off to start with then turn on when there is a collision with a tagged object here is my script
function Start() {
Orb.enabled = false;
}
var Orb : Light;
Orb.enabled = false;
function OnCollisionEnter(hit : Collision)
{
if (hit.gameObject.name == "bullet")
{
Orb.enabled = true;
}
}
the light doesn't turn on when collision is detected how can i fix this?
any suggestions/ amendments would be great
thanks
Have both your light and your bullet got a collider component? Does one of them have a non-kinematic rigidbody component?
i have a similar script which effects sound and that works fine and the bullet does have a collier
Answer by iamthecoolguy11 · Sep 28, 2014 at 06:50 PM
use active instead of enable
Orb.active = true;
i did this
function Start() {
Orb.active = false;
}
var Orb : Light;
Orb.active = false;
function OnCollisionEnter(hit : Collision)
{
if (hit.gameObject.name == "bullet")
{
Orb.active = true;
}
}
but it the light still doesn't come on
Answer by screenname_taken · Sep 29, 2014 at 10:26 AM
Perhaps it's an issue with your lights and their types. Is it set as important or not important? Also, are you in vertex lit or forward rendering? and If in forward, how many pixel lights are you allowing in your project settings?
Your answer
![](https://koobas.hobune.stream/wayback/20220613163942im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Raycast Destroys player. 1 Answer
GUI cale and position according to the actual screen resolution. 1 Answer
GUI.HorizontalSlider not working 2 Answers