• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jex4Life · Mar 23, 2014 at 11:09 PM · animationvariablebooleansfalsetrue

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");

} } } }

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FinKone · Mar 23, 2014 at 11:42 PM 0
Share

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?

avatar image Jex4Life · Mar 24, 2014 at 12:07 AM 0
Share

They are supposed to be pulled in an order

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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");
Comment
Add comment · Show 9 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jex4Life · Mar 24, 2014 at 12:08 AM 0
Share

Ok. Thank you. I'll give it a try.

avatar image Jex4Life · Mar 24, 2014 at 12:17 AM 0
Share

The door still doesn't open. I can pull all 3 levers, but nothing happens with the door. :(

avatar image Simon-Larsen · Mar 24, 2014 at 12:27 AM 0
Share

I'm assuming 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");
 }

}

avatar image Simon-Larsen · Mar 24, 2014 at 12:29 AM 0
Share

Also, make sure you actually enter the trigger

avatar image Jex4Life · Mar 24, 2014 at 12:41 AM 0
Share

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

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I make animations snap to a frame? 2 Answers

Boolean problem!! 2 Answers

Problems with save 1 Answer

Variables in animations 0 Answers

GUI Button to toggle true false when pressed 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges