Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Apr 24, 2016 at 12:47 PM by flaxor for the following reason:

fixed

avatar image
0
Question by flaxor · Apr 21, 2016 at 07:16 PM · animationscript.animator controller

cant trigger animation while jump

hi im trying make shot animation while jumping, the animation in ground is good. The problem is animation cant triggered when "player" in the air and the shot animation triggered after player touching ground.

this my controller:

alt text

and my code:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
     //speed move
     public float Speed;
 
     //jump var
     bool grounded = false;
     float groundcheckradius = 0.2f;
     public LayerMask groundlayer;
     public Transform groundCheck;
     public float jumpheight;
 
 
     Rigidbody2D myRB;
     Animator myAnim;
     bool facingRight;
 
     //shooooottttt
     public Transform fromwhere;
     public GameObject bullet;
     float firerate = 0.5f;
     float nextfire = 0f;
 
 
     void Start ()
     {
         myRB = GetComponent<Rigidbody2D>();
         myAnim = GetComponent<Animator>();
 
         facingRight = true;
     }
     
     // Update is called once per frame
 
     void Update()
     { 
         if(grounded && Input.GetAxis("Jump")>0)
         {
             grounded = false;
             myAnim.SetBool("isGrounded", grounded);
             myRB.AddForce(new Vector2(0,jumpheight));
         }
 
         //shot
         if (Input.GetAxis("Fire1") > 0)
         {
 
             shot();
             
         }
     }
     void FixedUpdate ()
     {
         //check if riki are grounded
         grounded = Physics2D.OverlapCircle(groundCheck.position, groundcheckradius, groundlayer);
         myAnim.SetBool("isGrounded", grounded);
 
         myAnim.SetFloat("verticalSpeed", myRB.velocity.y);
 
 
         float move = Input.GetAxis("Horizontal");
         myAnim.SetFloat("speed", Mathf.Abs(move));
 
         myRB.velocity = new Vector2(move*Speed, myRB.velocity.y);
 
         flip(move);
     }
 
     void flip(float move)
     {
         if (move > 0 && !facingRight || move < 0 && facingRight)
         {
             facingRight = !facingRight;
             Vector3 theScale = transform.localScale;
             theScale.x *= -1;
             transform.localScale = theScale;
         }
 
     }
 
     void shot()
     {
         if (Time.time > nextfire)
         {
             nextfire = Time.time + firerate;
             myAnim.SetTrigger("triggershot");
             if (facingRight)
             {
                 Instantiate(bullet, fromwhere.position, Quaternion.Euler(new Vector3(0, 0, 0)));
             }
             else if (!facingRight)
             {
                 Instantiate(bullet, fromwhere.position, Quaternion.Euler(new Vector3(0, 0, 180f)));
             }
             {
 
             }
         }
     }
 }
 

thanks for your help ^^

2016-04-22-01-19-01.png (35.5 kB)
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 Cherno · Apr 21, 2016 at 07:26 PM 1
Share

Probably a problem with your transition settings. Check exit time etc.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

the animation walk but he still in the same place and rotate left and right on this white circle 0 Answers

How do I use the same script on enemy ai's and play animations in the animator controller properly on unity3d 0 Answers

Aligning animation with movement. 0 Answers

How to play animation when player is moving? 2 Answers

How do you increase an animations speed through c# 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