- Home /
Button.onClick.AddListener(() => Attack()); isn't running function math correctly
I have a menu with multiple functions and settings so I am using the below code to switch methods via state, but something is going wrong with the math except when I associate the method with an input, so I know there's something wrong with the OnClick.AddListener I am using. Here's a video
 switch(currentBattleState){
 case (BattleStates.PLAYERCHOICE):
 // Seupt Battle Function
         
 Button1.SetActive(true);
 Button1text.text = "WaterPunch";
 Button1b.onClick.AddListener(() => Attack());
//----------------------------------------------------------
     if (Input.GetKeyDown(KeyCode.W))
         {
             Attack();
         }
//-----------------------------------------------------------
 public void Attack()
     {
         enemyHealth.battleEHealth -= 2 + (3 * levelUp.currentPlayerLevel);
     
     }    
 
 
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by hexagonius · May 31, 2015 at 02:11 PM
In the video the debug is rising for the "Player Choice", which means, that every time it's called, the Method is again added to the button. Add it just once at the beginning or something.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                