public void takeDamage(short damage) { health -= damage; if (transform.position.z < 0) { GameManagerPartie.instance.enemyDamage += damage; if (GameManagerPartie.instance.enemyDamage >= 1500) { AIeasy.changeState(AIeasy.AIState.Magic1); } } else { GameManagerPartie.instance.playerTotalDamage += (uint)damage; GameManagerPartie.instance.playerDamage += damage; if (GameManagerPartie.instance.playerDamage >= 1500) { GameManagerPartie.instance.SetMagic1Enable(); } } if (health <= 0) { die(); return; } //Debug.Log((float)health / (float)maxHealth); healthBar.fillAmount = (float)health / (float)maxHealth; }
void die() { //player kills /*GameManagerPartie.instance.playerKills++; * if (GameManagerPartie.instance.playerKills >= 5) * { * GameManagerPartie.instance.playerMagic2.GetComponent<Button>().interactable = true; * }*/ if (gameObject.GetComponent <playerMovement>() != null) { gameObject.SetActive(false); health = maxHealth; healthBar.fillAmount = (float)health / (float)maxHealth; if (transform.position.z < 0) { Vibrator.Vibrate(); GameManagerPartie.instance.enemyCoins += 50; GameManagerPartie.instance.enemyCoinsTxt.text = GameManagerPartie.instance.enemyCoins.ToString(); transform.position = GameManagerPartie.instance.playerPos; } else { GameManagerPartie.instance.playerCoins += 50; GameManagerPartie.instance.playerCoinsTxt.text = GameManagerPartie.instance.playerCoins.ToString(); transform.position = GameManagerPartie.instance.enemyPos; } //GameManagerPartie.instance.ChangeSprites(); Invoke("respawn", PlayerRespawnTime); } else { if (gameObject.GetComponent <towerBase>() != null) { if (transform.position.z < 0) { GameManagerPartie.instance.lose(); } else { GameManagerPartie.instance.win(); } Destroy(gameObject); } else { if (transform.position.z < 0) { GameManagerPartie.instance.enemyKills++; if (GameManagerPartie.instance.enemyKills >= 5) { AIeasy.changeState(AIeasy.AIState.Magic2); } } else { GameManagerPartie.instance.playerKills++; if (GameManagerPartie.instance.playerKills >= 5) { GameManagerPartie.instance.SetMagic2Enable(); } } if (gameObject.GetComponent <freezingTower>() != null) { gameObject.GetComponent <freezingTower>().reverse(); } Debug.Log(transform.position + " " + gameObject.name); Destroy(gameObject); positionManager.delete(transform.position); } } }