I’m working on a game for my portfolio class and I have poured over the forums and answers to get assistance with my issue. I’m now posting my question to get some answers from the community.
I have a destroy by contact script for my hero character, but I added a couple lines that would give the player a certain amount of lives and when he dies, the level would restart and when he reaches zero lives, then the game over screen would come up. The problem is that the player restarts over and over again but the game over screen never comes up when the player should be game over.
I got some of the script pieces from the forum, I’ve tried using Random.Range but then I get an error saying that I can’t turn an integer into a boolean.
using UnityEngine;
using System.Collections;
public class DbyContact : MonoBehaviour {
public GameObject explosion;
public GameObject playerExplosion;
public int scoreValue;
public int lives;
private GameController gameController;
void Start ()
{
GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
if (gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent <GameController>();
}
if (gameController == null)
{
Debug.Log ("cannot find 'GameController' script");
}
}
void OnTriggerEnter(Collider other) {
if (other.tag == "Boundary")
{
return;
}
if (other.tag == "pBullet")
{
return;
}
if (other.tag == "eBullet")
{
Instantiate(explosion, transform.position, transform.rotation);
lives -=1;
if (lives<=3)
{
Application.LoadLevel (Application.loadedLevel);
}
if (lives<=0)
{
Application.LoadLevel ("GameOver");
}
if (other.tag == "Enemy")
{
Instantiate (explosion, other.transform.position, other.transform.rotation);
lives -=1;
if (lives<=3)
{
Application.LoadLevel (Application.loadedLevel);
if (lives<=0)
{
Application.LoadLevel ("GameOver");
//Loser.Restart ();
}
}
//if (lives <= 0)
//{
// Application.LoadLevel ("GameOver");
//}
gameController.AddScore (scoreValue);
Destroy(other.gameObject);
Destroy(gameObject);
}
}
}
}