Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Dqimass · May 31, 2016 at 10:10 AM · playerdeathrestartpointsgameover

how to restart without time,.timescale effecting it

I have time.timescale = 0; turned on once the player dies. but if the player click restart, the game reloads. Why is the timescale still effecting the game when the game is restarting ><. how do I turn the timescale to normal again when player restart the game?

 void OnTriggerEnter2D(Collider2D other)
 {
          
     if (other.gameObject.CompareTag ("Player")) {
         Destroy (other.gameObject);
         Time.timeScale = 0;
         Replay ();

     }
 }

this is how my player dies upon collision with an obstacle. When player dies, the game was still running and the player still obtaining point even though the player is not active anymore. That why I've decided to freeze the game and click restart button

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
Best Answer

Answer by Zen_Hap · May 31, 2016 at 01:24 PM

script start:

using UnityEngine;

using System.Collections;

public class Hurt : MonoBehaviour {

 public int health = 1;

 void Start () {
     Time.timeScale = 1f;
 }
 
 void Update () {
     
     if (health <= 0){
         Die();
     }
 }
 
 void OnTriggerEnter(Collider other) {
     if (other.gameObject.tag == "Deadly") {
         health--;
     }
 }
 
 void Die () {
     Time.timeScale = 0f;
     Application.LoadLevel("DeathScreen");  #This is the death scene.
 }

}

:script end

Above code is called Hurt.cs, (Don't include script start: and :script end, they are just to show you what to copy) the code must be c#. Tag the player as Deadly and whatever kills the player as Deadly, then make sure they both have a collider set as trigger. If the thing that kills the player is a bullet, not another player or whatever, make sure the bullet has a trigger collider as well. Now if you save the script, add it to the thing that kills the player (e.g: bullet, zombie, bomb) and the player, once you have done that an option will pop up in the editor that says health, this is the health of the player from the public int in the script. Set the health to what you want but make sure that the health is the same on the player and the thing that kills the player. If it is set to three and you get shot in the game, the player takes three hits before he dies. Now make a new scene called DeathScreen . Once you have made it make a new js file with this script:

pragma strict

function OnMouseUp () { Application.LoadLevel("Game"); #This is the game scene. }

Add the js script to the Main Camera on the death screen. Once you have done that create a UI button (This is your restart button) and scroll down to On Click (), and click the plus icon. Drag the Main Camera into the slot in the inspector and select what you called the script. Now click play and test it, if you click restart it should take you to the game scene!

Now if you have done it right, it should work fine! Thanks!

(P.S: Please go on gamejolt and find my game called Buzzle, if you are on windows you will be able to download and play it! the death system works exactly the same way in Buzzle and the script I have shown you is the one that I made for Buzzle! Play Buzzle and tell me if you like it please! Look at how the death system runs in that and it should be fine note:(I forgot to add the event system for mega mode so the restart menu dosen't work from mega mode, but it works fine in regular mode! :P))

Thanks!

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 Dqimass · May 31, 2016 at 08:12 PM 0
Share

hey thanks, i'll be sure to check it out

avatar image
0

Answer by Quertie · May 31, 2016 at 12:52 PM

Just add:

 void Start()
 {
     Time.timeScale = 1;
 }

So that the game unfreezes when the scene is loaded! Hope this solves your issue :)

Comment
Add comment · Show 2 · 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 Dqimass · May 31, 2016 at 08:14 PM 0
Share

hey thanks quertie. I can't believe it was that simple and it took me forever to solve it

avatar image Zen_Hap Dqimass · May 31, 2016 at 09:05 PM 0
Share

I also used: Time.timeScale = 1f; In the void start, I just wanted to tell you how to d the damage aswell :)

I'm currently updating Buzzle and it's definately WIP but here is the link to how it is so far (I hope that you like it :) ): http://www.gamejolt.com/games/buzzle/138631

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

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

Related Questions

How do I make it so a death animation will play when I hit an enemy? 0 Answers

Object Player Movement stops working after Restarting Unity 0 Answers

death and respawn 0 Answers

Whats a good way to kill player if they go below a certain area? 2 Answers

Player doesn't die. 0 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