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 markzareal · Nov 08, 2014 at 09:24 AM · animationjavascriptanimator

I'm confused with the animator

So I've got multiple animations and if I press the right button it would transform from Idle State to Right. So here's my script;

 private var speed : float = 3;
 private var speed2 : float;
 var character : GameObject;
 var isBack : boolean;
 var isLeft : boolean;
 var isRight : boolean;
 var isIdle : boolean;
 var isFront : boolean;
 var Animator : Animator;
 private var hit : RaycastHit2D;
 
 function Update () {
     BlahBlah ();
     if(Input.GetMouseButtonDown(0)) {
         hit = Physics2D.Raycast(camera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
         if( hit.collider.gameObject.name == "Right")
         {
             speed2 = 1;
             Debug.Log("Clicked");
             isRight = true;
             Animator.SetBool("isRight", isRight);
             Animator.SetFloat("speed", speed2);
             BlahBlah ();
         }
     }
     if(Input.GetMouseButtonUp(0)) {
         isRight = false;
         isIdle = true;
         speed2 = 0;
     }
 }
   
 function BlahBlah () {
     if(isRight == true) {
         character.transform.position.x = character.transform.position.x += 1.25 *(speed * Time.deltaTime);
     }       
 }

So in the animator, I've set the condition of the transition from right to idle to *isIdle is true *isRight is false *speed is less than 0.01 alt text

but when I released the button it would stop moving along the x axis but it would continue to play the Right animation instead of transitioning to Idle. I don't know whats wrong with this scriptt here.

Edit: Found the answer(By myself) it was because I didn't sign the isIdle variable boolean to the animator boolean. I forgot to put Animator.SetBool ("isIdle", isIdle)

screen shot 2014-11-09 at 10.42.22 am.png (13.4 kB)
Comment
Add comment · Show 6
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 Mayank Ghanshala · Nov 08, 2014 at 09:35 AM 0
Share

put your code part

  Animator.SetBool("isRight", isRight);
                  Animator.SetFloat("speed", speed2);

outside Button Down and inside Update

avatar image markzareal · Nov 08, 2014 at 10:25 AM 0
Share

Nope, didn't work, still the same @$$anonymous$$ayank Ghanshala

avatar image Linus · Nov 08, 2014 at 10:50 AM 0
Share

Some pictures of the animator could help you get answer

avatar image markzareal · Nov 08, 2014 at 11:47 PM 0
Share

I don't find any pictures that could help me but do you know the answer? @Linus

avatar image b1gry4n · Nov 09, 2014 at 12:18 AM 0
Share

try rena$$anonymous$$g your animator component. I think Animator as Animator is causing issues. try

 var anim: Animator;

I know for a fact that na$$anonymous$$g convention works because i use it all the time.

 anim.SetBool("isRight", isRight);
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Nov 08, 2014 at 09:33 AM

In your if(Input.GetMouseButtonUp(0)) {}, you don't ever set the Animator conditions again. I suspect you meant something like:

 if(Input.GetMouseButtonUp(0)) {
   isRight = false;
   isIdle = true;
   speed2 = 0;
   Animator.SetBool("isRight", isRight);
   Animator.SetFloat("speed", speed2);
 }
Comment
Add comment · Show 1 · 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 markzareal · Nov 08, 2014 at 10:25 AM 0
Share

Nope, didn't work, still the same

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

29 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

2D Animation Effects Velocity Wrong? 0 Answers

Animator preventing correct spawn position? 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