Hello,
Yes, trivial issue for some, but for some reason I am not seeing how its subtracting two from the score after second collision. I have a method void OnTriggerEnter(Collider other)
I have an if statement based on a tag
//When player collides we need to take the actions below
if (other.CompareTag ("Player"))
{
//the explotion animation and audio will occur
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
if(gamecontroller.life > 0)
{
//Subtract life from player
[B] [/B]gamecontroller.life--;
//Notify user of player destruction, Instiate new player after timer
gamecontroller.DeadPlayer();
}
else
{
//No Life left game over
gamecontroller.GameOver();
}
}
I have a GameController script and as you can see I subtract each time and then I call a method called DeadPlayer()
//When player is destroyed change value of variable to true
public void DeadPlayer()
{
StartCoroutine(DeadPlayerPause());
}
I am sure there is a better way, but this works, than I StartCoroutine so I can pause before new object is Instantiated.
//DeadPlayer trying to pause before starting again if player still has lifes.
IEnumerator DeadPlayerPause()
{
deadPlayer = true;
gameOverText.text = "Ship Destroyed, don't give up, Keep fighting";
yield return new WaitForSeconds(7);
gameOverText.text = "";
Instantiate(Player);
StartCoroutine(SpawnWaves());
}
}
I can’t figure out where the double count is coming from, anyone have any ideas? If I am missing some code that may help, let me know.
Spawn wave that makes the items drop randomly.
//This is how we spawn the enemy objects and randomly have the falling on screen.
IEnumerator SpawnWaves()
{
yield return new WaitForSeconds(startWait);
while (true) {
for (int i = 0; i < hazardCount; i++) {
GameObject hazard = hazards[Random.Range(0, hazards.Length)];
Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
Quaternion spawnRotation = Quaternion.identity;
Instantiate(hazard, spawnPosition, spawnRotation);
yield return new WaitForSeconds(spawnWait);
}
yield return new WaitForSeconds(waveWait);
//This will break the while loop and prevent more enemies from being spawned.
if (gameOver)
{
restartText.text = "Press 'R' for Restart or 'Q' to Quit";
restart = true;
break;
}
//This will break the while loop and prevent more enemies from being spawned.
if (deadPlayer)
{
deadPlayer = false;
break;
}
}
}