Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Ishmail Hoque · Aug 14, 2014 at 10:06 PM · gamestop

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!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rutter · Aug 14, 2014 at 11:50 PM 1
Share

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).

avatar image PaulOrac · Aug 16, 2014 at 05:15 PM 0
Share

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?

avatar image Ishmail Hoque · Sep 01, 2015 at 09:21 PM 0
Share

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!

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Kiwasi · Aug 15, 2014 at 12:19 AM

 if(playerIsDead){
     Application.Quit();
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image D3Duck · Sep 01, 2015 at 09:36 PM 0
Share

That's just going to completely close the game... Don't think that's what OP is trying to do

avatar image Ishmail Hoque · Nov 17, 2015 at 02:40 PM 0
Share

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.

avatar image DavidRoad Ishmail Hoque · Feb 17 at 02:09 PM 0
Share

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");
 }
avatar image
1

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ishmail Hoque · Nov 17, 2015 at 02:41 PM 0
Share

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.

avatar image
0

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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how can i create survey form in game 0 Answers

how to manually control angle of sun while in game? 1 Answer

joystick android 3d , help. 0 Answers

Simple Drag and Drop Jigsaw - Help! 0 Answers

Prefab doesn't spawn on android 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges