How to make the game stop upon death?
I am making a game and I urgently need to know how to make my game stop(including counter) when I die.
This is my enemy script.
using UnityEngine;
using System.Collections;
public class Cubes : MonoBehaviour {
public float delay = 0.1f;
public GameObject cube;
// Use this for initialization
void Start () {
InvokeRepeating("Spawn",delay,delay);
}
// Update is called once per frame
void Spawn () {
Instantiate(cube,new Vector3(Random.Range(-6,6),10,0),Quaternion.identity);
}
public bool readyToKill = false;
}
All help will be greatly appreciated! Thanks in advance!
Unity doesn't know what "death" is, so you'll have to program that behavior in, yourself:
Figure out what actions you want to stop once the player dies
Stop doing them
If you want some script to stop updating? Disable it. If you want some GameObject to go away? Destroy or deactivate it.
You could have some scripts watch if the player is alive or not. $$anonymous$$aybe they react once the player dies (ie: showing a scoreboard), or maybe it's enough for some of them to just stop updating (ie: AI freezes).
hey there! I'll try to help you. What is the counter you want to stop? What do you mean by stopping the Game? Do you wish to quit the game when loosing or maybe pausing it and showing a button to restart? Or maybe something else?
What I am trying to do is when the enemy hits the player the player dies but my main problem is making the player respawn back and without a respawn script I cannot have a counter. I've tried many things like loading the level after death but it wont work. I guess its because the enemy is a script compiled thing and isn't an object. Anyway, replies are great!
Answer by Kiwasi · Aug 15, 2014 at 12:19 AM
if(playerIsDead){
Application.Quit();
}
That's just going to completely close the game... Don't think that's what OP is trying to do
That would just quit the game, thats not what I want. i just want something that makes the character spawn back or a menu that comes up to retry or something. Along those lines would be great.
i know i might be late but ummm this was the code you had to try
if(playerIsDead)
{
Application.LoadLevel("The Level You Want To Go To");
}
Answer by Noxury · Oct 11, 2015 at 09:52 PM
If you mean by stopping the game like when you open a pause menu, then Time.timescale = 0
might be the solution for you. From there you can fade in a game over window on the canvas to let the user play again or whatever options are available.
I want it when the player dies then the whole game stops as well as the timer and opens a menu to restart or something.
Answer by Ishmail Hoque · Nov 17, 2015 at 02:38 PM
I have the player as the game object and I have the script for the enemy that makes the enemy spawn. As the script of the cubes are not a game object and just a script, how do I make it that when the player hits the script (in a way) the player dies or spawns back? Thanks for any help!
Your answer
![](https://koobas.hobune.stream/wayback/20220613160629im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How I sent someone my project,without him getting unity? 1 Answer
How to reset player position when a ball hits the goal box? 0 Answers
Android screen resolution by Export bug 0 Answers
how can I make it rotate depending on the position of the player? 0 Answers
Noob: Fresh install play/stop problem 0 Answers