- Home /
Game restarting even though it's not called.,My game will restart when not called.
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
bool gameHasEnded = false;
public void EndGame ()
{ if (gameHasEnded == false)
{
gameHasEnded = true;
Debug.Log("GAME OVER");
Restart();
}
}
void Restart ()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
$$anonymous$$an, very bad post.
You are calling the function somewwhere, 100% sure.
Answer by ATLGAN · Mar 02, 2020 at 05:48 AM
If you using Visual Studio, if you press Shift + F12, you can see the references using this method.
Answer by Batuhan13 · Mar 02, 2020 at 05:10 AM
Hi mate =) @tormentoarmagedoom is right you are proably missing somewhere but it is easy to find where you miss =) .Firstly could you try to disable all c# scripts in your scene when you do this game shouldnt be restarted anymore .Then could you check your c# scripts in your scene which have a connection with your GameManager.EndGame() function .Problem is proably that in some script there is a line which calls void EndGame(){} or which calls void Restart(){} .Good luck and have fun =)
using UnityEngine;
public class PlayerCollision : $$anonymous$$onoBehaviour { public Player$$anonymous$$ovement movement;
void OnCollisionEnter(Collision collisionInfo)
{
{
if (collisionInfo.collider.tag == "Obstacle")
movement.enabled = false;
FindObjectOfType<Game$$anonymous$$anager>().EndGame();
}
}
}
It's only supposed to call Obstacles.
Your answer
![](https://koobas.hobune.stream/wayback/20220612224233im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
restart level of car game 2 Answers
while i restart the game,it hangs. why so? 3 Answers
How to restart scene with trigger? 1 Answer
Trouble with restarting 2D tutorial 2 Answers
Raising hazard killing player 0 Answers