Ennemy don't lose life [C#]
Hello Everybody ! I'm creating a little game where ennemies goes to a castle and you are a tower who defend the castle. But I have a problem... When my ennemy is touching the castle, the castle lose 1 life but when my bullet touch the ennemy, he don't lose life... I created a empty child for the collider of my ennemy, and one for my bullet but it doesn't work.... This is my ennemy script
using UnityEngine; using System.Collections;
public class Ennemy : MonoBehaviour { private NavMeshAgent agent; public static int lvl = 1; public static double Damage; public static double Vies = 10;
void Start () {
lvl = 1;
agent = GetComponent<NavMeshAgent>(); //déplacement
//NavMeshPath chemin = new NavMeshPath();
agent.destination = GameObject.Find ("Castle").transform.position; //sa destination est la postition de "castle"
}
void Update () {
Damage = GameManager.Damage;
Vies = 10 + (lvl * 3);
//////////////////////////////////////////////////////////// VIES PAR LEVEL
if (GameManager.score >= 250){
lvl = 2;
}
if (GameManager.score >= 500){
lvl = 3;
}
if (GameManager.score >= 750){
lvl = 4;
}
if (GameManager.score >= 1000){
lvl = 5;
}
if (GameManager.score >= 2250){
lvl = 6;
}
if (GameManager.score >= 2500){
lvl = 7;
}
if (GameManager.score >= 2750){
lvl = 8;
}
if (GameManager.score >= 2000){
lvl = 9;
}
if (GameManager.score >= 2250){
lvl = 10;
}
if (GameManager.score >= 2500){
lvl = 11;
}
if (GameManager.score >= 2750){
lvl = 12;
}
if (GameManager.score >= 3000){
lvl = 13;
}
if (GameManager.score >= 3250){
lvl = 14;
}
if (GameManager.score >= 3500){
lvl = 15;
}
if (GameManager.score >= 3750){
lvl = 16;
}
if (GameManager.score >= 4000){
lvl = 17;
}
if (GameManager.score >= 4250){
lvl = 18;
}
if (GameManager.score >= 4500){
lvl = 19;
}
if (GameManager.score >= 4750){
lvl = 20;
}
if (GameManager.score >= 5000){
lvl = 21;
}
if (GameManager.score >= 5250){
lvl = 22;
}
if (GameManager.score >= 5500){
lvl = 23;
}
if (GameManager.score >= 5750){
lvl = 24;
}
if (GameManager.score >= 5000){
lvl = 25;
}
if (GameManager.score >= 5250){
lvl = 26;
}
if (GameManager.score >= 5500){
lvl = 27;
}
if (GameManager.score >= 5750){
lvl = 28;
}
//////////////////////////////////////////////////////////// VIES PAR LEVEL
if (Vies <= 0) {
Destroy(this.gameObject);
GameManager.argent += 1;
GameManager.score += 5;
}
}
void OnTriggerEnter (Collider col){
if (col.gameObject.name == "Castle") {
TextVie.vie--;
Destroy (this.gameObject);
}
if (col.gameObject.name == "Bullet(Clone)") {
Vies -= Damage;
Destroy (col.gameObject);
}
}
}
Thank you very much, that reading my post, i hope some one can help me.... Bye, xyHeat
Answer by SneakySquid · Jan 17, 2016 at 10:31 AM
From what I can tell, you are losing health/Vies, but in your Update function, you have
Vies = 10 + (lvl * 3);
This keeps resetting Vies to this value, so you never lose any health/Vies
Your answer
Follow this Question
Related Questions
How to make an enemy 2d chasing player? 2 Answers
I need the Nav Mesh Stop , I need the Animation to Play Javascript 0 Answers
how to make an enemy into a second player 0 Answers
Advance AI ( League of Legends ) 0 Answers
How do I make an enemy go through walls, etc and follow then kill the player? 0 Answers