0
\$\begingroup\$

I had used a tutorial to set up the attack, but is was only for one attack. I tried to modify it for a combo, but it plays all the animations at once. How can I change this to work as a 3-hit combo?

public class Combat : MonoBehaviour
{

    Animator anim;
    PLayercontreols inputs;
    private bool canhit1 = true;
    private bool canhit2;
    private bool canhit3;
    // Start is called before the first frame update
    private void Awake()
    {
        anim = GetComponent<Animator>();
        inputs = new PLayercontreols();
        inputs.Player.Attack.performed += Attack;
      
    }

    private void Attack(InputAction.CallbackContext obj)
    {   if (canhit1 == true) 
        { 
         StartCoroutine(Attack()); 
        }
        if(canhit2 == true)
        {
            StartCoroutine(Attack2());
        }
        if (canhit3 == true)
        {
            StartCoroutine(Attack3());
        }
    }

    private void OnEnable()
    {
        inputs.Enable();


    }



    private void OnDisable()
    {
        inputs.Disable();
    }
    void Start()
    {
        
    }
    private System.Collections.IEnumerator Attack()
    {
        anim.SetLayerWeight(anim.GetLayerIndex("Overide layer"), 1);
        anim.SetTrigger("Attack1");
        canhit2 = true;
        canhit1 = false;
        yield return new WaitForSeconds(0.9f);
        anim.SetLayerWeight(anim.GetLayerIndex("Overide layer"), 0);
      
        
        canhit2 = false;
        canhit1 = true;
    }
    private System.Collections.IEnumerator Attack2()
    {
        
        anim.SetTrigger("Attack2");
        canhit3 = true;
        canhit1 = false;
        yield return new WaitForSeconds(0.9f);
        anim.SetLayerWeight(anim.GetLayerIndex("Overide layer"), 0);

        
        canhit3 = false;
        canhit1 = true;
    }
    private System.Collections.IEnumerator Attack3()
    {

        anim.SetTrigger("Attack3");
        canhit1 = false;
        yield return new WaitForSeconds(0.9f);
        anim.SetLayerWeight(anim.GetLayerIndex("Overide layer"), 0);
        canhit1 = true;


    }
    // Update is called once per frame
    void Update()
    {
        
    
\$\endgroup\$
6
  • \$\begingroup\$ Searching "Unity 3 hit combo tutorial" turns up lots of leads. Have you considered using a guide tailored to this feature instead of adapting one that is not? \$\endgroup\$
    – DMGregory
    Dec 16, 2021 at 21:32
  • \$\begingroup\$ i did but didnt work \$\endgroup\$ Dec 16, 2021 at 21:34
  • \$\begingroup\$ What specifically did not work? \$\endgroup\$
    – DMGregory
    Dec 16, 2021 at 21:37
  • \$\begingroup\$ The whole thing animation wouldnt work and it caused errors \$\endgroup\$ Dec 16, 2021 at 21:42
  • \$\begingroup\$ Sounds like you implemented it incorrectly. Without seeing your implementation and the specific errors, we cannot tell you what you did that was incorrect. \$\endgroup\$
    – DMGregory
    Dec 16, 2021 at 21:44

0

You must log in to answer this question.

Browse other questions tagged .