- Home /
Light effects on collision
Hi there,
I have attached a flashing script to a directional light and wish to queue the light to enable after a collision later on in the scene. Any ideas as to how to best do this??
Many thanks
Answer by GC1983 · May 27, 2012 at 06:34 AM
A flashing light? You could just set a timer to turn the object off and on. LightObject.light.enabled = false/true; should be correct. Just set a deltaTime timer on Update().
Thanks Greg, I now get the error: Assets/Scripts/LightTrigger.js(4,9): BCE0005: $$anonymous$$ identifier: 'LightObject'.
$$anonymous$$y code thus far is:
var flashinglight: GameObject;
function Awake(){
LightObject.light.enabled = false;
}
function OnTriggerEnter(trigger: Collider){
LightObject.light.enabled = true;
}
flashingLight is your LightObject. flashingLight.light.enabled = true;
I'm still getting errors...? I went to this page: http://unity3d.com/support/documentation/ScriptReference/Light.html to get some scripting but not sure if that was the right thing to do?
var flashinglight: GameObject;
var enabled: boolean = false;
function OnTriggerEnter(trigger: Collider){
flashinglight.light.enabled = true;
}
I am getting this error: $$anonymous$$issingComponentException: There is no 'Light' attached to the "WaterDay(Trigger)" game object, but a script is trying to access it. You probably need to add a Light to the game object "WaterDay(Trigger)". Or your script needs to check if the component is attached before using it. LightTrigger.Update () (at Assets/Scripts/LightTrigger.js:13)
I have attached my directional light to the var created in the inspector panel... So I'm not sure what I'm missing??
Code: var flashinglight: GameObject;
var intensity: float;
var duration: float = 1.0;
var enabled: boolean = false;
function OnTriggerEnter(trigger: Collider){
flashinglight.light.enabled = true;
}
function Update() {
var phi : float = Time.time / duration * 2 * $$anonymous$$athf.PI;
var amplitude : float = $$anonymous$$athf.Cos( phi ) * 0.5 + 0.5;
light.intensity = amplitude;
}
Your answer
Follow this Question
Related Questions
Police Flashing Lights? 4 Answers
How to make flashing/blinking/flickering lights? 1 Answer
Police flashing light script 2 Answers
Disabling objects from Collision detection 1 Answer
Done Everyyyy thing but OnCollision is not working!! 1 Answer