Game freezes and crashes everytime the player dies and I press the restart button
Hi Friends, I would like to have your opinion on what could be the problem I have facing. I have been working on this big pc game and I sort of ended up being stuck when I press the restart button to restart the level. So i tested with two different levels and imported the character and the terrain only in the second scene and as soon as it gets on the seconds scene it just freezes. This does this either it is in the editor or the built. So I started digging abit and realize that everytime that my player's slider life reaches to 0, and brings up the menu to restart the game, that is when the issue erupt. Whenever I do decide to restart the level at anytime before the player is completely dead, everything reloads fine and can move and stuff... So I am not sure how exactly would be the best way to fix this and still have the player die and reload the scene fine. Is it a bug in unity or something else? Can someone kindly share a solution? I also checked what goes on in the inspector, I realize that when i press restart, every single objects show deleted.
We need more information. Give us your GameOver script and your PlayerHealth script.
Are you using Application.LoadLevel? If you aren't, are any non-instantiated GameObjects being destroyed on player death?
Answer by kimardamina · Sep 03, 2015 at 08:31 AM
Hi BlackSnow, thanks for the reply. I am using Application.LoadLevel indeed. Here is the script used for the player's death which is attached on the enemy.
Here is the script attached on the enemy which reduces the blood of the main character on Trigger:
public var mainCharacSlider:UI.Slider;
public var mainMenu:GameObject;
//play hit audio sound
public var stebAudio:AudioSource;
public var bloodFlick:GameObject; //Show the blood flickering on the screen
function Awake(){
mainMenu = gameObject.Find("MainMenu");
mainMenu.SetActive(false);
bloodFlick.SetActive(false);
}
function Start () {
mainCharacSlider.value = 10.0f;
}
function Update(){
var sliderValue = mainCharacSlider.value;
/*if(Input.GetKeyDown("z")){
// this is just to test
mainCharacSlider.value -= 0.1f;
}*/
if(sliderValue < 0.1f){
mainMenu.SetActive(true);
//Time.timeScale = 0;
}
}
//reduce the slider value when hitting the main character
function OnTriggerEnter (col:Collider) {
if(col.gameObject.CompareTag("Player")){
mainCharacSlider.value -= 0.1f;
stebAudio.Play();
// activate the blood on the screen
BloodFlicker();
} else {
return;
}
}
//function to flicker the blood option
function BloodFlicker(){
bloodFlick.SetActive(true);
yield WaitForSeconds(0.2);
bloodFlick.SetActive(false);
}
Then the menu pops up and it has a button to restart the game since you have died, and the script for that button is:
function RestartGame(){
Application.LoadLevel(Application.loadedlevel);
}
I also tried to go back to another level by using the normal Application.LoadLevel("Name of the scene"), but as long as it had got the main character who as the slider it just freezes.
@BlackSnow_2 thank you for your assistance
Have you tried using the scenes' index number ins$$anonymous$$d? You can find it under File > Build in the top box (If it's not there click "Add current scene to list" or something of the sort).
@BlackSnow_2, I did try the numbering. The thing is it loads but nothing moves. the only object active are the backtrack sound, and if you put any button on there it will also be able to be pressed. Like UI elements work but no GameObject and script
What does your movement script look like? This is a really odd issue and I honestly cannot see why your game would be freezing or crashing.
The crazy part is that not only the charcter script stops. Like every single thing just stands still. Would you want me to send you a video maybe? I have scratched my head trying to understand this but nothing works
Your answer
Follow this Question
Related Questions
Changing Graphic Levels Causing Crash 1 Answer
How to lock slider increase? 1 Answer
link GUI slider to shader opacity 0 Answers