Pressing Keys in a Specific Order

Hi! I am making a game involving magic and I have a great idea how to cast spells. But I don’t know what to write. This is what I want the console to say (not exactly).

//User pressed and is holding E, Starting Spell recognision

//Pressed LeftClick

//Pressed LeftClick

//Pressed RightClick

//Pressed LeftClick

//User let go of E, Recognising spell

//Spell is “Fire”, Casting spell

BTW: Code can be in any language as long as you explain what each part does and what I need to change to add more spells.

Use Input.GetKeyDown and Input.GetKeyUp to determine when the user starts and stops holding the ‘E’ key down.

Then use Input.GetMouseButtonDown while E is being pressed to read mouse clicks. Note that:

button values are 0 for left button, 1
for right button, 2 for the middle
button.

While tracking the clicks, add ‘L’ and ‘R’ to a “Spell String”.

Then you just have to check it against your library of spell strings.

var fireBallSpell = "LLRLLRRL";

if(inputSpell == fireBallSpell)
{
  castFireBall();
}

This can just be solved with bools or stages.
User holding down E can be handled like so

private bool eIsHeldDown = false;
public int FireSpellStage = 0;

void Update(){
  eIsHeldDown = Input.GetKey(KeyCode.E);
  if(eIsHeldDown){
       if(FireSpellStage == 0 ){
             if(Input.GetKeyDown(KeyCode.F)){
             FireSpellStage = 1;
             }
             else if (FireSpellStage == 0){
                    if(Input.GetKeyDown(KeyCode.I)){
                           FireSpellStage = 0;
                     }
            } 
           // And So on, till you made a combo you like. 
        }

  }
else{
     if(FireSpellStage == 4){
          Debug.Log("Casting Fire Spell");
     }
FireSpellStage = 0;
}
  
}

WUC (warrning, uncompiled code, check for errors. )