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 nathanvj · Aug 26, 2013 at 06:55 PM · animationnewbie

I try'd so hard, but my animation script doesnt work..?

**I'm a newbie with scripting.. But I tried my best to get my animation's working on the right time.. I wanted to

  • play my run animation when left shift is pressed and we were not walking or idle

  • to play my idle when you are not running / walking

  • to play my walk animation when were not running or idle

This may be a dumb question, but this script get this error: Expressions in statements must only be executed for their side-effects. Here is the script:**

 #pragma strict
 
 var idle : boolean = false;
 var walking : boolean = false;
 var running : boolean = false;
 
 function Update () {
 
 //make the idle animation play when you are not walking or running
     if(walking == false && running == false)
     {
     animation.CrossFade('Idle');
     idle == true;
     running == false;
     walking == false;
     }
 
 
 //Make the walk animation play when you are not Idle or running
     if(Input.GetKey(KeyCode.W))
     {
     animation.CrossFade('Walk');
     walking == true;
     running == false;
     idle == false;
     }
 
 //Make the run animation play when you are not Idle or walking
     if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.W))
     {
         animation.CrossFade('Run');
         running == true;
         idle == false;
         walking == false;
     }
 
 //Make the walk animation stop when the W key is released
     if(Input.GetKeyUp(KeyCode.W))
     {
     animation.Stop('Walk');
     walking == false;
     running == false;
     idle == true;
     }
 
 //Make the run animation stop when the left-shift key is released.
     if(Input.GetKeyUp(KeyCode.LeftShift))
     {
     animation.Stop('Run');
     running == false;
 }
 
 //Make the run or walk animation stop when you are not running or walking
     if (Input.GetKeyUp(KeyCode.LeftShift) && Input.GetKeyUp(KeyCode.W))
     {
         animation.CrossFade('Idle');
         running == false;
         idle == true;
         walking == false;
     }
 
 }

Some-one who can help me get this working? :(

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ZenithCode · Aug 26, 2013 at 07:08 PM

Use == only as a relational operator (Check if they are equal).

For the rest use a single = sign.

E.g:

 if(walking == false && running == false)
 {
     animation.CrossFade('Idle');
     idle = true;
     running = false;
     walking = false;
 }
Comment
Add comment · Show 4 · 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 nathanvj · Aug 26, 2013 at 07:18 PM 0
Share

Thank you so much! I'll check asap if this works. ;-)

avatar image nathanvj · Aug 26, 2013 at 07:36 PM 0
Share

$$anonymous$$y animation doesn't play and the booleans don't go back to idle?

 #pragma strict
 
 var walking : boolean = false;
 var idle : boolean = false;
 var running : boolean = false;
 
 function Update () {
 
         //if W is pressed, change booleans.
         if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.W))
         {
         walking = true;
         running = false;
         idle = false;
         }
     
         //if W and LeftShift are pressed, change booleans
         if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.W) && Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift))
         {
         walking = false;
         running = true;
         idle = false;
         
         //if W is released, change booleans
         if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.W))
         {
         walking = false;
         running = false;
         idle = true;
         }
 
         //if statement to play Idle animation.
         if(walking == false && running == false && idle == true)
         {
         animation.Play('Idle');
         Debug.Log('you have no movement');
         }
 
         //if statement to play run animation.
         if(walking == false && idle == false & running == true)
         {
         animation.Play('Run');
         Debug.Log('you are running');
         }
 
         //if statement to play walk animation.
         if(walking == true && idle == false && running == false)
         {
         animation.Play('Walk');
         Debug.Log('you are walking');
         }
     }
 }
avatar image nathanvj · Aug 27, 2013 at 08:48 AM 0
Share

Why my script (in comment) isn't working :(

avatar image ZenithCode · Aug 27, 2013 at 09:02 AM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class AnimationController : $$anonymous$$onoBehaviour
 {
 
     private enum AnimationStates
     {
         idle,
         walk,
         run
     }
     
     private AnimationStates _animationState;
  
     void Update ()
     {
  
         //if W is pressed, walk
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.W)) {
             _animationState = AnimationStates.walk;
         }
  
         //if W and LeftShift are pressed, go back to idle
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.W) && Input.Get$$anonymous$$ey ($$anonymous$$eyCode.LeftShift)) {
             _animationState = AnimationStates.idle;
         }
         
         //if W is released, change booleans
         if (Input.Get$$anonymous$$eyUp ($$anonymous$$eyCode.W)) {
             _animationState = AnimationStates.idle;
         }
  
         switch (_animationState) {
         case AnimationStates.idle:
             {
                 Debug.Log ("Idle");    
                 animation.Play ("Idle");
                 break;
             }
         case AnimationStates.walk:
             {
                 Debug.Log ("Walk");    
                 animation.Play ("Walk");
                 break;
             }
         case AnimationStates.run:
             {
                 Debug.Log ("Run");    
                 animation.Play ("Run");
                 break;
             }
         
         }
     }
 }

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

16 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

Related Questions

Animated Texture Offset 1 Answer

How do I add NPCs? 2 Answers

i need a help in script to move while he is animation? 2 Answers

How to click a 3d object in unity3d? 3 Answers

Stop animation on the time given then start animation when press a key 0 Answers


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