Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by bman85 · Oct 25, 2013 at 06:02 AM · javascriptcollisionguidestroy

Game Over GUI Question

I have a game in which the first person controller is destroyed when the player enters into a collider of an enemy. I also have a game over GUI script that I want to run when the player dies. I have tried using Boolean variables, but the player is destroyed and the scripts are destroyed too so I have not found a good way to do so. What is the best way to have a player die without destroying it? Or what is a good way to create Game Over GUI?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Azrapse · Oct 25, 2013 at 06:40 AM

You know, man, death doesn't have to be THAT bad. It can be mostly a state of mind... :)

Now seriosly, instead of actually destroying the player controller, make dead "just a state of mind". That is, add a bool IsDead property to the player character.

When it's false, the game runs as usual.

When it's set to true, make the camera unattach itself from the player character (or stop following it, or whatever you are doing), and make the player character disable it's renderers and it's scripts (by setting their enabled field to false).

That will make the character disappear and stop processing input, and colliding, etc. Then you can move the camera somewhere else or make a Game Over UI appear with buttons for restarting or quitting.

Restarting would do something like:

  • Place the character object back to starting position.

  • Reset its stats (health, ammo, whatever).

  • Reenable all its components and renderers. It will make it appear and start running its scripts and collide and everything.

  • Attach the camera back to it, or make it follow it again, or whatever you do with your camera.

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
avatar image
0

Answer by fafase · Oct 25, 2013 at 06:54 AM

Create a GameManager that can set the state of the game and reports it.

 public enum State{Running, Pause, Over}
 public class GameManager
 {
     public State gameState;
     void Start(){
         _gaemeState = State.Running;
     }
 }

Then create an empty game object and add this to it. From any script that needs to know the state of the game:

 public GameManager manager;
 
 void Update(){
    if(manager.gameState == State.Pause)return;
    if(health = 0) 
    {
        manager.gameState = State.Over;
        Destroy(gameObject);
    }
 }

In the Pause script

 public GameManager manager;
 void OnGUI(){
    if(manager.gameState == State.Over)GameOverGUI();
 }

You can also make each level to inherit from GameManager so that it is a manager itself and has access to all other members you would add.

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

16 People are following this question.

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

Related Questions

Destroying a prefab on collision with a cube? 1 Answer

Why doesn't Destroy work? 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Destroy cube on collision 1 Answer

On Click, destroy object and any colliding object with the same tag. 6 Answers


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