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 ZieViox · Sep 17, 2015 at 10:54 AM · playermecanimtimecomboattacking

Fixing Animation calls in a combo Script

The problem is that

the combo animation plays when its combo number "ComboInt" and it's own animation number "PlayerCurrentCombo" matches the ones I've set to it

each animation has these 2 variables

and a combo would contain many animations

and should be running when you press the right key in the right time

"timeLastKeyPressed" "allowedTimeBetweenKeys"

the problem is that only the first animation plays and it gets stuck, doesn't even get back to idle animation

it should be a combo script for one like DmC

This is the script:

 using UnityEngine;
 using System.Collections;
 
 public class ComboSie : MonoBehaviour {
     
     // Here type the sequence of KeyCodes for your special combo.
     private KeyCombo combo1 = new KeyCombo(new KeyCode[] { KeyCode.Q, KeyCode.E, KeyCode.E });
     private KeyCombo combo2 = new KeyCombo(new KeyCode[] { KeyCode.E, KeyCode.E });
     public Animator ComboCont;
     public static Animator PlayerAnimator;
     
     void Awake()
     {
         //PlayerAnimator = (Animator) GameObject.FindGameObjectWithTag("Player").GetComponent(typeof(Animator));
         PlayerAnimator = ComboCont;
         Debug.Log (ComboCont);
         Debug.Log (PlayerAnimator);
         
     }
     void FixedUpdate()
     {
         //PlayerAnimator.applyRootMotion = true;
         if (combo1.Check())
         {
             PlayerAnimator.SetInteger("ComboInt",1);
             /*
             if(PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Combo1") && !PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Combo2") )
             {
                 PlayerAnimator.SetBool("ComboPlaying",true);
                 PlayerAnimator.SetInteger("ComboInt",1);
             }
             // Play the 'combo1' special combo.
             */
         }
         if (combo2.Check())
         {
             PlayerAnimator.SetInteger("ComboInt",2);
             /*
             if(PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Combo2")  && !PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Combo1") )
             {
                 PlayerAnimator.SetBool("ComboPlaying",true);
                 PlayerAnimator.SetInteger("ComboInt",2);
             }
             */
         }
         
         /*if(!PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Combo1") && PlayerAnimator.GetBool("ComboPlaying")  == true)
         {
             PlayerAnimator.SetBool("ComboPlaying",false);
             PlayerAnimator.SetInteger("ComboInt",0);
         }
         if(!PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Combo2") && PlayerAnimator.GetBool("ComboPlaying")  == true)
         {
             PlayerAnimator.SetBool("ComboPlaying",false);
             PlayerAnimator.SetInteger("ComboInt",0);
         }
         */
     }
     public class KeyCombo
     {
         //public Animator PlayerAnimator = (Animator) GameObject.FindGameObjectWithTag("Player").GetComponent(typeof(Animator));
         public Animator PlayerAnimator;
         
         public KeyCode[] Keys;
         private int currentIndex = 0; //moves along the array as Keys are pressed.
         
         public float allowedTimeBetweenKeys = 1f; //tweak as needed.
         private float timeLastKeyPressed;
         
         public KeyCombo(KeyCode[] b)
         {
             Keys = b;
             
         }
         public bool Check()
         {
             Debug.Log (ComboSie.PlayerAnimator);
             PlayerAnimator = ComboSie.PlayerAnimator;
             
             if (Time.time > timeLastKeyPressed + allowedTimeBetweenKeys)
                 currentIndex = 0;
             if (currentIndex < Keys.Length)
             {
                 if (Input.GetKeyDown(Keys[currentIndex]))
                 {
                     Debug.Log(PlayerAnimator);
                     timeLastKeyPressed = Time.time;
                     currentIndex++;
                     
                     Debug.Log ( "Playing Animation" );
                     Debug.Log ( currentIndex );
                     Debug.Log ( PlayerAnimator.GetCurrentAnimatorStateInfo (0).IsName("Combo1") );
                     //Here play the animation according to your combo sequence AND your currentIndex.
                     PlayerAnimator.SetInteger("PlayerCurrentCombo",currentIndex);
                     return true;
                 }
                 if (currentIndex >= Keys.Length)
                 {
                     PlayerAnimator.SetInteger("PlayerCurrentCombo",0);
                     currentIndex = 0;
                     //Here play the last animation and the special combo animation OR just play the special combo animation.
                     //return true;
                 }
                 else return false;
             }
             return 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

30 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

Related Questions

Simple attack knockback: How to get two trigger colliders to interact? 1 Answer

Help with system inputs for a combo game. 0 Answers

Continuous Attack Damage to Enemy [HELP] 0 Answers

Play button not playing the game. BIG PROBLEM(Solved) 1 Answer

How to make so when i press the left mouse button the 3D model attacks, and when i press it again it makes the next attack animation and the next total of 3 animations in a row like a combo click animations? 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