Different attacks using same keybindings?

I’m designing a rather simple combat system driven by animations.

I’m trying to create a couple of attacks with the following keybinds:

Mouse 1 = Simple Attack
Mouse 2 = Different Simple Attack
LeftCtrl + Mouse1 = Power Attack.

However, Unity seems to register only the mouseclick when I’m holding LeftCtrl.
I’m almost certain this is just down to me being a noob at coding.

using UnityEngine;
using System.Collections;

public class Attack : MonoBehaviour {
    Animator anim;

    void Awake()
    {
        anim = GetComponent<Animator>();
    }

    void Update()
    {
        if (anim.GetBool("CombatStance") == true)
        {
            if (Input.GetKeyDown(KeyCode.LeftControl) && Input.GetButtonDown("Fire1"))
            {
                anim.SetTrigger("LeftPowerAttack");
            }
            else if (Input.GetButtonDown("Fire1"))
            {
                anim.SetTrigger("LeftAttack");
            }
            else if (Input.GetButtonDown("Fire2"))
            {
                anim.SetTrigger("RightAttack");
            }

        }
    }
}

GetKeyDown, registers ONCE when the user actually presses the key stroke, doesnt have to lift their finger off the key, just as soon as the computer registers “Left Control was pressed”, it considers it down, it doesnt check “Left Control is still down” – thats what GetKey does, itll continue to send “Left Control is held down” rather then “Left Control is pressed”.

So you could try structuring your if-statements to look like:

if (Input.GetKey(KeyCode.LeftControl) && Input.GetButtonDown("Fire1"))
             {
                 anim.SetTrigger("LeftPowerAttack");
             }
             else if (Input.GetButtonDown("Fire1"))
             {
                 anim.SetTrigger("LeftAttack");
             }
             else if (Input.GetButtonDown("Fire2"))
             {
                 anim.SetTrigger("RightAttack");
             }

Hope that helps.

Hello Decreationist,

Based on that code, the LeftPowerAttack should be happening. I haven’t messed around with checking two inputs within a single if statement, but as I said, that should be working. Two options for improvement immediately come to mind: 1. You could nest the check for leftcontrol, so like

         if (Input.GetButtonDown("Fire1"))
         {
             if(Input.GetKeyDown(KeyCode.LeftControl)){
                         anim.SetTrigger("LeftPowerAttack");
              }
              else{
                         anim.SetTrigger("LeftAttack");
         }

should work.

  1. You could have Left control be stored in a different boolean variable and have it check that instead of the actual GetKeyDown.

I also just noticed that you’re using GetButtonDown for fire1, which would work if you have it set up as a button. As far as I am aware, though, “fire1” is defaultly an Axis, which means that you would measure it as a float with a range from -1 to 1. You would check this by typing if(Input.GetAxis(“fire1” > 0f))

You can go into Edit > Project Settings > Input to change whether or not it is an Axis