Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 Jaxor · Oct 23, 2014 at 07:56 PM · beginnersequence

Beginner has a problem with sequence ;)

Hi everybody :)

Something's wrong with my code. I'm trying to make some kind of sequence by pressing GUI button: First step, is the animation of falling bomb. Then, after 2 sec. from the beginning of those animation, the scene is changing to another ("ExplosionTest"). And that's all. Two steps.

Console shows me: "WARNING: Boolean expression will always have the same value." I'm trying to make this problem for two days but I can't. Where is mistake? What I have to do to make it work? Any sugestions? Thanks a lot :)

 var Bomb : GameObject;
 var Anim : Animation;
 var Expl : boolean;
  
 function Start(){
     Anim = Bomb.GetComponent(Animation);
 }
  
 function OnGUI(){
     
     if(GUI.Button (Rect(1000, 570, 200, 100), "Fire")) {
         Bomb.animation.Play("Fall", PlayMode.StopAll);
     }
 }
 
 function CoUpdate(){
     if(Bomb.animation.Play);
 
 yield WaitForSeconds(2);
      {
       Application.LoadLevel("ExplosionTest");
       }
    }  
Comment
Add comment · Show 1
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 N1warhead · Oct 23, 2014 at 09:17 PM 0
Share

Not sure if this is right, but it might help if you declare your boolean somewhere lol.

All I see is just the Variable at the time, I don't see it anywhere else.

Like in C# (should be very very similar to Unityscript if not the exact same!)

Do something like (in your GUI Button) After Bomb Animation put

 Expl = true;


then in your CoUpdate put

 if(Expl && Bomb.animation.Play){
 
  yield WaitForSeconds(2);
 {
 Application.LoadLevel("ExplosionTest");
 Expl = false;
 }
 } 


What I just did was declare the Expl bool as true when button is pressed, then in your CoUpdate put (If Expl & your animation is playing) then do the rest of the code. Then changed Expl back to false.

I hope that helps!

Not sure if that will fix your problem, but I hope it does.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by disc330 · Oct 24, 2014 at 01:52 AM

The cause of the warning is the line: if(Bomb.animation.Play);

The member "Bomb.animation.Play" is a method, and I think in Javascript, by simply existing, it will resolve to true. (Don't quote me on that, I'm a C# man!)

I assume that you meant to use something more like: "if(Bomb.animation.isPlaying)" in your "CoUpdate" method.

Comment
Add comment · 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
0

Answer by Habitablaba · Oct 23, 2014 at 09:25 PM

Play returns if the animation was able to play or not. It does not return if the animation is playing which I'm guessing is how you are meaning for it to be used in your CoUpdate method.
The Animation class has an IsPlaying method for that.

Beyond that, you have some syntax errors in your CoUpdate method around your if statement.

 function CoUpdate(){
   if(Bomb.animation.IsPlaying("Fall")){
     yield WaitForSeconds(2);
 
     Application.LoadLevel("ExplosionTest");
   }
 } 

Since you don't show it anywhere, I'm also unconvinced that you are starting the CoRoutine that is supposed to run CoUpdate.

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I reset a variable? 2 Answers

How can I start unity fast with my C++ engine 2 Answers

Scripting a Konami Code 1 Answer

Best Unity Practices 1 Answer

Assets/Scripts/Cubemove.js(44,167): BCE0017: The best overload for the method 'UnityEngine.Mathf.Round(float)' is not compatible with the argument list '(boolean)'. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges