- Home /
how do i make when i click on a candle it out and when i click back on it, it's light?
i want to make a candle light and out when i click out it using scripts(Java), for a menu i am trying to make, how do i do this?
Information on Light :
http://docs.unity3d.com/Documentation/ScriptReference/Light.html
http://docs.unity3d.com/Documentation/ScriptReference/Behaviour-enabled.html?from=Light
http://docs.unity3d.com/Documentation/Components/class-Light.html
Information on Raycast :
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
Video Links :
http://www.unity3dstudent.com/2010/07/essentials-e08-lights/
http://www.unity3dstudent.com/2010/08/intermediate-i01-raycasting/
Here are some links I strongly suggest to all new users :
Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/essential-skills/
Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/beginner/
this is the YouTube link for the above as one playlist : http://www.youtube.com/watch?v=-oXYHNSmTxg&list=PL27B696FB515608D2&feature=plcp
I recommend learning raycast, personal experience found On$$anonymous$$ouse functions unreliable, and you can get alot of information from a RaycastHit. When you have built your candle prefab, enable/disable it with SetActiveRecursively for unity 3.x, for Unity 4 use SetActive
Answer by smirlianos · Jan 08, 2013 at 04:28 PM
Try using this script, that sets the light intensity. It's inside the OnMouseUp function, so the code runs when the user clicks the candle (like the Main Menu). Then if the variable isOnLight is true, it sets the intensity of the light to zero, and if it's not true, it sets the intensity back to 1. Be sure to put a collider in the candle!
(note: I wrote ths script now, so mabey there are some mistakes)
private var isOnLight : boolean;
function OnMouseUp() {
if(isOnLight)
{
light.intensity = 0.0;
yield;
isOnLight = false;
}
else if(!isOnLight)
{
light.intensity = 1.0;
yield;
isOnLight = true;
}
}
i guess it won't work because i can a candle, light, and two particle system to make a fire on the candle so it won't work but thanks aways.
if there is not only the light but all this, try this, that makes the candle(or any part of this, disapear)
private var isOnLight : boolean;
var obj1 : GameObject;
var obj2 : GameObject;
var obj3 : GameObject;
function On$$anonymous$$ouseUp() {
if(isOnLight)
{
light.intensity = 0.0;
yield;
isOnLight = false;
obj1.active = false;
obj2.active = false;
obj3.active = false;
}
else if(!isOnLight)
{
light.intensity = 1.0;
yield;
isOnLight = true;
obj1.active = true;
obj2.active = true;
obj3.active = true;
}
}