if statement wont execute on health < 0;
hi
i have a part of game where if a certain score is hit it changes boss to fight. problem is in the if statement, when the boss dies,
bosshealth = 100(set it in inspector); /full script bellow
ive tryed: if (0 >= bosshealth.health) { Debug.Log("1"); Invoke("something", 0); } // if ( bosshealth.health <= 0) ... // if ( bosshealth.health <= any number abovezero) ...
not even debug shows up.
then i tryed setting if ( bosshealth.health >= anything up to 100) and it works. i dont know why???????????? ive tryed just exiting unity still nothing. boss does NOT get destroyed before invoke. i need invoke so player can see what happens to boss.,
  boss spawn script:
 it's in Update.
 // move player to boss
 if (scoreCount >= 100 && scoreCount <= 150 && scoreIncreasing == true)
         {
             scoreIncreasing = false;
             bossOne.gameObject.SetActive(true);
             player.transform.position = new Vector3(-2400, 0, -360);
             player.Rotate(new Vector3 (0, -90, 0));
             bosshealth = bosshealth.GetComponent<bossOneHealth>(); // yes it is set in inspector
             if (0>= bosshealth.health)
             {
                 Invoke("something", 5);
             }
 
         }
 
 void something()
     {
 Debug.Log("3");
                 player.transform.position = new Vector3(0, 0, 0);
                 player.Rotate(new Vector3(0, 90, 0));  
     }
 
 
 bosshealthscript:
 public void takeDamage(int damage)
     {
         health = health - damage;
         if(health <= 0)
         {
             damaged.gameObject.SetActive(false);
             damaged1.gameObject.SetActive(false);
             damaged2.gameObject.SetActive(false);
             damaged3.gameObject.SetActive(false);
             StartCoroutine("explodeAnim"); //lasts 6 seconds
         }
     }
 
i found a way around it. ins$$anonymous$$d of invoking after destroying boss through boss spawn script, ive placed code and modified to go through bosshealthscript.
 public void takeDamage(int damage)
     {
         health = health - damage;
         if(health <= 0)
         {
             damaged.gameObject.SetActive(false);
             damaged1.gameObject.SetActive(false);
             damaged2.gameObject.SetActive(false);
             damaged3.gameObject.SetActive(false);
             StartCoroutine("explodeAnim");
      
         }
     }
 
     public IEnumerator explodeAnim()
     {
         destroyedAnim.gameObject.SetActive(true);
         yield return new WaitForSeconds(5f);
         destroyedAnim.gameObject.SetActive(false);
         myS$$anonymous$$ = myS$$anonymous$$.GetComponent<$$anonymous$$yScore$$anonymous$$anager>();
         player.transform.position = new Vector3(0, 0, 0);
         player.Rotate(new Vector3(0, 90, 0));
         myS$$anonymous$$.scoreCount += 51;
         myS$$anonymous$$.scoreIncreasing = true;
         Lean.LeanPool.Despawn(transform.parent.gameObject);
     }
i still dont get why the original script doesnt work. ive also tryed making another public int in spawnscript(scoremanager) and then making it = to health. it was matched but still nothing happened.
I still want to know why this wasnt working from the start. So please answer if anyone knows as this is baffling. Also, I dont want to mark my own answer as the correct answer. XD
Your answer
 
 
             Follow this Question
Related Questions
mathf.abs(0) is higher than 90, why? 1 Answer
Compare a value to all other values in an array 2 Answers
Check a bool method with if statement 1 Answer
Two IF Statements not working in one method 2 Answers
If statement not working correctly 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                