- Home /
Created an Open Close Animation, but script wont activate both doors?
I have a sliding door, i already made the 2 animations for each door. Open and Close, i have the collider set as a trigger, and a sound on the trigger object. When i walk into the collider i hear the sound but only the right door slides open? And if i exit the collider i only the right door slides closed.
SO why is the left door not opening? it is animated properly i tested it. I added them in order under Animation: 1,2,3,4
private var enter : boolean;
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") {
enter = true;
animation.Play("SlidingDoors");
animation.Play("SlidingDoors3");
audio.Play();
}
}
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player") {
enter = false;
audio.Play();
animation.Play("SlidingDoors2");
animation.Play("SlidingDoors4");
}
}
Any help would be nice, it's driving me crazy i must have missed something. Update: SlidingDoors = Left Door/Open, SlidingDoors3 = Right Door/Open. SlidingDoors2 = Left Door/Close, SlidingDoors4 = Right Door/Close.
are the animations stored on the doors themselves or the parent of them? if the animations are stored on the separate doors you need to add the script to the left door as well.
@ $$anonymous$$oor, (where u added this script,). Umm as i said above i have it on my Trigger Object.
@ Fornoreason1000, i tried several variations of that. 2 triggers/1 trigger both doors as children it just would not work.
But i got it solved now thanks to ( GameVortex ) below!
@TheGeekyDead:
I removed the "solved" in the title since that's not part of the question. A question should not include an answer or anything related to an answer. A question is marked as solved by picking an answer (which you already did).
I also removed all of your tags. Tags should represent your actual problem with short keywords. Things like "help", "code", "error" or "script" are useless. I've replaced them with more appropriate ones.
Also, ppl, don't forget to vote (i don't talk to TheGeekyDead since he can't vote yet). If no one votes questions up all those who just ask questions but don't post answers never get any karma. So you can't get upvotes from the person.
We have really a lot bad and very bad questions here, but this one is clearly a good one.
edit
I'm just wondering where's the facebook and youtube generation? It's kind of strange that on StackOverflow votes are kind of spammed around, but here it looks like people fear they could loose something if they vote something up.
I don't want to make you spam votes, this is a knowledge base and everyone who thinks he can judge if a question / answer is good should vote.
Answer by GameVortex · Nov 24, 2013 at 08:58 AM
You are playing both your animations on the same object. This means that when you play the animation "SlidingDoors3" it stop the other animation "SlidingDoors" from happening. I would recommend separating them out and have the animations play on their own objects. Something like this maybe:
private var enter : boolean;
public var leftDoor : GameObject;
public var rightDoor : GameObject;
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") {
enter = true;
leftDoor.animation.Play("SlidingDoors");
rightDoor.animation.Play("SlidingDoors3");
audio.Play();
}
}
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player") {
enter = false;
audio.Play();
leftDoor.animation.Play("SlidingDoors2");
rightDoor.animation.Play("SlidingDoors4");
}
}
Remember to assign your doors in the inspector.
Ahh thanks man, i knew i was missing something. So i had to define each door as an object, i had all 4 animations on the trigger it's self lol. /Facepalm
So i Updated the script, and i had to re-make the animations for each door, because they reset for some odd reason when placing it on a new object. (Animation: Practice makes perfect) i was able to make them look way better when opening this time and the ti$$anonymous$$g. But now it works 100% i walk up it beeps and the doors slide open, i leave the trigger it beeps and they slide closed!
I even tested it with my enemy AI, when he wanders up it activates the error code "lights flash" (doors lock) and the guns shoot him and i have to disable the alarm. (i updated the script since i posted it) i added a lot more stuff like my Alarm+$$anonymous$$eypad.
But thanks for the help. i will keep that in $$anonymous$$d for future objects and switches with more than one animation haha.