When my bullet collides with the spider it minuses 1 from the SpidersLeft(SeperateClass)but if i set spidersleft to 10 it goes down to 9 but then goes back to 10 instead of going down to 8 then 7 then 6 and so on.
My EnemyStats Class;
using UnityEngine;
using System.Collections;
public class EnemyStats : MonoBehaviour {
public int SpidersLeft = 0;
void Start () {
SpidersLeft = 10;
}
}
My Bullet Class
using UnityEngine;
using System.Collections;
public class Bullet_Settings : MonoBehaviour {
public GameObject spawnSpider1;
public GameObject SecondKey;
EnemyStats enemyStats;
public int SpidersLeft;
GameObject player;
void Start () {
player = GameObject.FindGameObjectWithTag("Player");
enemyStats = player.GetComponent<EnemyStats>();
}
void OnTriggerEnter (Collider hit){
if(hit.gameObject.tag == "Spider1"){
SpidersLeft = enemyStats.SpidersLeft;
Destroy(hit.gameObject);
Destroy(gameObject);
if (SpidersLeft > 0){
SpidersLeft-=1;
Instantiate(spawnSpider1);
}
else if(SpidersLeft == 0)
Instantiate(SecondKey);
}
}
}