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 Demigoth · Jun 02, 2014 at 02:36 AM · animationanimator controllerparameters

switch animation from blend tree

Hi guys, so I got a question for using an animator controller in 2D. Ok so I got these animations (Run, Walk, Idle, Jump and Death) all of them are simple except jump that uses a blend tree. From code I call to them when needed. But when a condition is met I call the Death animation from the any state block. The problem is it works correctly on every animation except on the Jump state. If I am jumping when the conditions are met then nothing happens and no animation is played.

To be precise I got only the Death Animation on atomic. and the code that controls everything is here.... So any help would be greatly appreciated.

 sing UnityEngine;
 using System.Collections;
 
 public class RunnerCharacter2D : MonoBehaviour {
 
     // Public variables
     public Transform groundCheck;
     public UISlider freshBar;
 
     // Private variables
     private bool _facingRight = true;
     private float _maxSpeed = 10f; 
     [SerializeField] private float _jumpForce = 400f;
     private bool _airControl = false;
     [SerializeField] private LayerMask _whatIsGround;
     private float _groundedRadius = 0.2f;
     private bool _grounded = false;
     private Animator _anim;
     private float _maxFresh = 3f; 
     private float _freshness;
     private bool _hasRotten;
 
     void Awake() {
         _anim = GetComponent<Animator>();
         _freshness = _maxFresh;
         _hasRotten = false;
     }
 
     void Start() {
         _anim.SetBool("Alive", true);
     }
 
     void FixedUpdate() {
         _grounded = Physics2D.OverlapCircle(groundCheck.position, _groundedRadius, _whatIsGround);
         _anim.SetBool("Ground", _grounded);
         _anim.SetFloat("vSpeed", rigidbody2D.velocity.y);
     }
 
     void Update() {
         _freshness -= Time.deltaTime;
         freshBar.value = _freshness / _maxFresh;
         if (_hasRotten == false) {
             if (freshBar.value <= 0) {
                 _anim.SetBool("Alive", false);
                 NotFresh ();
                 _hasRotten = true;
             }
         }
     }
 
     public void Move(bool _jump, float move) {
         if (_grounded || _airControl) {
             _anim.SetFloat("Speed", Mathf.Abs(move));
             rigidbody2D.velocity = new Vector2(move * _maxSpeed, rigidbody2D.velocity.y);
             if(move > 0 && !_facingRight) {
                 Flip();
             } else if (move < 0 && _facingRight) {
                 Flip();
             }
         }
 
         if (_grounded && _jump) {
             _anim.SetBool("Ground", false);
             rigidbody2D.AddForce(new Vector2(0f, _jumpForce));
         }
     }
 
     void Flip ()
     {
         // Switch the way the player is labelled as facing.
         _facingRight = !_facingRight;
         
         // Multiply the player's x local scale by -1.
         Vector3 theScale = transform.localScale;
         theScale.x *= -1;
         transform.localScale = theScale;
     }
 
     public void NotFresh () {
         StartCoroutine(PlayDeathOnce("nFresh"));
     }
 
     public IEnumerator PlayDeathOnce (string paranName) {
         _anim.SetBool (paranName, true);
         yield return null;
         _anim.SetBool (paranName, false);
     }
 }
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

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

Controlling animator parameters from timeline 0 Answers

unity freezes when running sprinting animation 0 Answers

Animator parameters 1 Answer

Removing blending between two animations for only certain parameters 1 Answer

Player freezes because of Animator 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