Hi everyone, I’m currently working on a horror game and I’ve being spending hours by making scenes and models. I’ve learned about Mesh Colliders a few months ago and how the “Is Trigger” function works. I’ve placed a bunch of ceiling lamps to make my scene look brighter and what I need, as the title says; A script for being able to toggle lights when closing up an object (For example, clicking the E button to open/close lights when near the light switch)
I’ve setup my Capsule Collider with his appropriate scale and range plus with the “Is Trigger” function checked, and yes, my point light is attached with my ceiling lamp.
If you guys have great ideas for making a kind of script like this, please post them as an answer below! I would really appreciate your supports 
As always, thanks!
-crusherxman
1 Answer
1
this can be simply done in javascript with a .active statement. for example :
var Lights : GameObject;
var InArea : boolean = false;
var LightsOnAndInArea : boolean = false;
var LightsOffAndInArea : boolean = false;
function Start ()
{
Lights.active = true;
}
function Update ()
{
if(Input.GetKeyDown(KeyCode.E) && LightsOnAndInArea == true){
Lights.active = false;
}
if(Input.GetKeyDown(KeyCode.E) && LightsOnAndInArea == false){
Lights.active = true;
}
if(Lights.active == true && InArea == true){
LightsOnAndInArea = true;
}
if(Lights.active == false && InArea == true){
LightsOnAndInArea = false;
}
if(Lights.active == true && InArea == false){
LightsOnAndInArea = false;
}
if(Lights.active == false && InArea == false){
LightsOnAndInArea = false;
}
}
function OnTriggerEnter (other : Collider)
{
InArea= true;
}
function OnTriggerExit (other : Collider)
{
InArea= false;
}
There you go now you can toggle on and off
Daphoeno
You don't need another animation. Do as Cherno said and use CrossFade, it'll smoothly transition from idle to walk for you.
– alexguerinsure i need..this crossfade only make the transition smooth...but it will me more realistic if there are animation transition..most of third person game have it...gta, saint row, do you ever play them? not just idle to walk they also have walk to idle and run to idle and even more..i think its a standard feature for third person games nowaday...
– indra_pWell, in that case, I don't undestant what the problem is. You already know how to create and play animations, so just create a new transition animation, and play it before playing the walking/ruuuning animation.
– ChernoActually, most games DON'T have a manually created transition between every animation pair. Most use a tweening technique (such as Unity's CrossFade) to automatically generate the "animation" on the fly, which is a much more robust system. Also, post things like this as a comment, not an answer.
– Hoeloe