if (hitPoints <= 0) {
// When no more hp, i want to make the game stop running and display a GUItext Game Over!
}
How to script to make the game stop running but without closing the game immediately?
if (hitPoints <= 0) {
// When no more hp, i want to make the game stop running and display a GUItext Game Over!
}
How to script to make the game stop running but without closing the game immediately?
Do you mean to pause the game? If so you could use the command
if (hitPoints <= 0) {
guiTexture.enabled = true;
Time.timeScale = 0;
}
// HP script on player
var hitPoints = 20;
var damageAmount = 2;
var ouchText : GameObject;
var hpText : TextMesh;
var diesound : AudioClip;
var gameoverText : GameObject;
function Start() {
if (hpText) {
hpText.text = hitPoints.ToString();
}
}
function OnTriggerEnter(other : Collider) {
Debug.Log("Trigger hit");
if (other.CompareTag("Finish")) {
ApplyDamage(damageAmount);
Destroy(other.gameObject);
}
}
function ApplyDamage(damageAmount : int) {
hitPoints = hitPoints - damageAmount;
if (ouchText) {
ouchText.active = true;
}
if (hpText) {
hpText.text = hitPoints.ToString();
}
if (hitPoints <= 0) {
// Display Game Over and Stop the game.
if (gameoverText) {
gameoverText.active = true;
}
}
if (diesound){
AudioSource.PlayClipAtPoint(diesound, transform.position);
}
}
This is the script. I tried using the Time.timeScale = 0 but after doing it for 1 time, and when i try to run the game again for second try it still paused. It won’t refresh? I need to code Time.timeScale = 1 in order to make the game start running again Otherwise, it wont run anymore. After that, i’m going to make a (Try Again) button, once the user clicks the game will start again.
That is right, you have to bring the time scale back to 1 to make it run at normal speed again. Add the line Time.timeScale = 1; under your function Start.
function Start() {
Time.timeScale = 1;
if (hpText) {
hpText.text = hitPoints.ToString();
}
}
Great, running smoothly right now…thanks~!
What about colliding with an object you don’t want your object to collide with?
Seriously, you are posting zero code and an obtuse weird question to a 13-year-old post?!
Make your own new post, it’s free.
And here is how to report your problem productively in the Unity3D forums:
how to make the game stop?
if (sunSize <=320) {
sunSize.enabled=true;
sunSize.timeScale = 0; (i want the game to stop when the sunSize is 320)
This is a post from 2007! Please do not necro posts like this, put some effort in and create your own thread.
Thanks.