- Home /
What am I doing wrong? Boolean-Animation Help please
Good afternoon,
I am trying to have my door open after 3 levers are pulled. Everything works, except the door opening. What am I doing wrong?
Here is my Script:
var Yellow_Lever : boolean = false;
var Blue_Lever : boolean = false;
var Green_Lever : boolean = false;
function OnTriggerStay ()
{
if ( Input.GetButtonDown("Fire1") )
{
transform.animation.Play("Yellow_Lever");
Yellow_Lever = true;
if ( Input.GetButtonDown("Fire1") )
{
transform.animation.Play("Blue_Lever");
Blue_Lever = true;
if ( Input.GetButtonDown("Fire1") )
{
transform.animation.Play("Green_Lever");
Green_Lever = true;
if
(
(Yellow_Lever == true)
(Blue_Lever == true)
(Green_Lever == true))
transform.animation.Play("Door_Open");
} } } }
Not entirely sure - I use C#...
Yellow_Lever == true && Blue_Lever == true && Green_Lever == true
Why not make all turn true on fire1 click anyways?
Answer by Simon-Larsen · Mar 23, 2014 at 11:44 PM
I'm not quite sure if your if statement syntax is correct. If you wish to check for multiple statements use the AND or OR operator. Try using this if statement.
if (Yellow_Lever && Blue_Lever && Green_Lever)
transform.animation.Play("Door_Open");
You can combine these operators in different ways as well. Say you wanted the door to open if both the yellow lever and the blue levet was pulled, but also wanted the door to open whenever the green lever was pulled.
if ((Yellow_Lever && Blue_Lever) || Green_Lever)
transform.animation.Play("Door_Open");
The door still doesn't open. I can pull all 3 levers, but nothing happens with the door. :(
I'm assu$$anonymous$$g you have compiler errors. Atleast your brackets aren't inclosed correctly. Remove(backup) all you code and paste this in: var Yellow_Lever : boolean = false; var Blue_Lever : boolean = false; var Green_Lever : boolean = false;
function OnTriggerStay () {
if (Input.GetButtonDown("Fire1")) {
transform.animation.Play("Yellow_Lever");
Yellow_Lever = true;
}
if (Input.GetButtonDown("Fire1")) {
transform.animation.Play("Blue_Lever");
Blue_Lever = true;
}
if (Input.GetButtonDown("Fire1")) {
transform.animation.Play("Green_Lever");
Green_Lever = true;
}
if (Yellow_Lever && Blue_Lever && Green_Lever) {
transform.animation.Play("Door_Open");
Debug.Log("Door has opened");
}
}
with the above script in place, I'm getting
"The animation state Door_Open could not be played because it couldn't be found! Please attach an animation clip with the name 'Door_Open' or call this function only for existing animations. UnityEngine.Animation:Play(String) Door_Open:OnTriggerStay() (at Assets/Scripts/Door_Open.js:25)"
BUT: $$anonymous$$y animations are in place. Caps is all checked and everything. The only triggers I have are in front of the Levers
Your answer
Follow this Question
Related Questions
Can I make animations snap to a frame? 1 Answer
Problem using mecanim and the Animation process 0 Answers
Check if var is true from a random object 0 Answers
Boolean while looking at a game object? 1 Answer
true and false wont work! 4 Answers