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 /
  • Help Room /
avatar image
0
Question by Dalsia · Jul 03, 2017 at 08:47 PM · animationanimatorcharactercontrollerscriptingbasics

How do I transition among multiple animations?

Hi, everyone,

I have been able to create a character movement script that allows me to trigger some individual animations based on inputs, such as jumping, idle and shooting arrows. I was wondering if there was a way to allow a single input, such as pressing the shoot button, to trigger multiple animations so that my character may shoot his bow, then transition to an "alert" state before going back to idle. Basically I want:

attack animation plays --> alert animation plays --> goes back to idle animation after a few seconds (alert animation would loop a few times) if no other attacks have been performed, but the alert stance can go back to the attack animation if the player decides to attack, starting the cycle all over again

Thank you for any help you can give me.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by theANMATOR2b · Jul 04, 2017 at 12:07 AM

Mecanim is kind of created exactly for this type of set up and others. I'd strongly suggest getting into it and learning how to control the transitions with code. However if you'd still like to keep using your script - you'll have to show/explain how it is currently set up so others can provide input on how to proceed.

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 Dalsia · Jul 04, 2017 at 03:25 AM

Thank you for responding. I'm having trouble figuring out how to do things like allowing my "alert" animation to keep being transitioned to if my player has attacked in the past 5 seconds. I have been able to make my character shoot his bow then play the alert animation, but if I walk during this animation and stand still I go back to idle when I'd like to go back to alert for 5 seconds after the character shoots his bow. I'm also having trouble with allowing my player to shoot his bow again once he is in the alert animation.

Here is my current script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class player_1_controller : MonoBehaviour {
 
     //movement variables
     public float maxSpeed;
 
     //jumping variables
     bool grounded = false;
     float groundCheckRadius = 0.2f;
     public LayerMask groundLayer;
     public Transform groundCheck;
     public float jumpHeight;
 
     Rigidbody2D myRB; 
     Animator myAnim;
     bool facingRight;
 
     //arrow shooting variables
     bool firing = true;
     public float arrowShoot;
     public Transform arrowTip;
     public GameObject arrow;
     public float fireRate = 0.5f;
     public float nextFire = 0f;
 
     //alert variables
 
     // Use this for initialization
     void Start () {
         
         myRB = GetComponent<Rigidbody2D> ();
         myAnim = GetComponent<Animator> ();
         facingRight = true;
     }
     
     // Update is called once per frame
     void Update () {
         
         if (grounded && Input.GetButtonDown ("Jump")) {
             grounded = false;
             myAnim.SetBool ("isGrounded", grounded);
             myRB.AddForce (new Vector2 (0, jumpHeight));
         }
 
         //player shooting
         if (grounded && Input.GetButtonDown ("Fire1")) {
             myAnim.SetBool ("arrowShoot", firing);
             Invoke ("fireArrow", 1);
             }
     }
 
         void FixedUpdate() {
         
         //check if we are grounded - if not, then we are falling
         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 * maxSpeed, myRB.velocity.y);
 
         if (move > 0 && !facingRight) {
             flip ();
         } else if (move < 0 && facingRight) {
             flip ();
         }
 
     }
             
         void flip () {
         facingRight = !facingRight;
         Vector3 theScale = transform.localScale;
         theScale.x *= -1;
         transform.localScale = theScale;
 
     }
 
     void fireArrow() {
 
         if (Time.time > nextFire) {
             nextFire = Time.time + fireRate;
             if (facingRight) {
                 Instantiate (arrow, arrowTip.position, Quaternion.Euler (new Vector3 (0, 0, 0)));
             } else if (!facingRight) {
                 Instantiate (arrow, arrowTip.position, Quaternion.Euler (new Vector3 (0, 0, 180)));
             }
         }
         playerAlert ();
   }
 
     void playerAlert () {
 
         firing = false;
         myAnim.SetBool ("arrowShoot", firing);
     }
 }
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

215 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 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 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 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 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 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 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 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

animation scirpting 1 Answer

Simple call animation then destroy? 0 Answers

How do I play an animation? 1 Answer

My 3D Character Moves to Other Spot When I Press Play 2 Answers

How to make player rotate 180° and run that direction with mecanim + vice versa? 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