[HELP] Gamepad Melee Attack

Hello Guys,
I am trying all day to figure out how can I damage enemies by using gamepad controller button or Key not camera raycaster.

for now I make :

void Update() {
        
        if (CrossPlatformInputManager.GetButton("Fire3")||Input.GetKey(KeyCode.X)) {         
            if((Time.time - lastAttack) > AttackCooldown)
              { 
            print("X");
                
                enemy.Health = (enemy.Health - attackDamage);
                lastAttack = Time.time;
      
            }
        }

What basicly makes print when I press X on keyboard on gamepad, also cooldown works but I am not able to change health of enemies and unity says … Can sameone help me how can I change parameters in other class?

Thanks for all help!

Privacy & Terms