The actual collision part works but the part that doesn’t work is the remainingEnemyShips variable. It always gives back 4 but doesn’t go lower.
private int remainingEnemyships;
void Start() {
//Getting the name of the current scene.
Scene currentScene = SceneManager.GetActiveScene ();
string sceneName = currentScene.name;
//Confirming that the active scene is Scene1
if (sceneName == "Scene1") {
remainingEnemyships = 5;
}
}
void OnCollisionEnter2D (Collision2D col) {
if (col.gameObject.tag == "EnemyShip") { //If bullet hits enemy ship
remainingEnemyships = remainingEnemyships - 1; //Decreasing the variable by 1
Debug.Log(remainingEnemyships); //Always gives back the number 4
Destroy(col.gameObject);
Destroy(gameObject);
}
}
}