Restarting Scene/Level
Hi, I'm begginer and i have problem. I want restart my scene. I have one Scene ("MainScene") and when a player dies i would like to restart game.
I tried used :
Application.LoadLevel(0);
SceneManager.LoadScene(0);
and both work but when i press space it automatically restart my scene and here is my problem, why space button is restarting my scene?
Answer by RabbitLeLe · Feb 11, 2017 at 11:32 AM
public class CanLose : MonoBehaviour {
public MobControler[] mc;
public Canvas loseMenu;
void Start()
{
loseMenu = (Canvas)GetComponent<Canvas>();
loseMenu.enabled = false;
}
void Update()
{
for (int i = 0; i < 42; i++)
{
if (mc[i].zdrowie <= 0)
{
loseMenu.enabled = true;
}
}
}
public void TryAgain()
{
loseMenu.enabled = false;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
Time.timeScale = 1;
SceneManager.LoadScene(0);
}
}
It's my code and TryAgain function in project is a text button. And after press TryAgain it should reload my scene (game) and it does but when i press space it reloads too. So here is code where I use space button:
public class PlayerControler : MonoBehaviour {
public CharacterController characterControler;
public float height_jump = 7.0f;
public float cur_height_jump = 0f;
void Start()
{
characterControler = GetComponent<CharacterController>();
}
void Update()
{
keyboard();
}
private void keyboard()
{
if (characterControler.isGrounded && Input.GetButton("Jump"))
{
cur_height_jump = height_jump;
}
else if (!characterControler.isGrounded)
{
cur_height_jump += Physics.gravity.y * Time.deltaTime;
}
Debug.Log(Physics.gravity.y);
}
}
Your answer
Follow this Question
Related Questions
Unable to Compile scripts on my game but my Team mates can on their machines?CS0103 0 Answers
Text adventure game, how to change text in a specific way with C# 1 Answer
I want my UI rawimage to do something when the movie texture has finished 1 Answer
¿Utilizar muchas escenas puede poner un juego lento? 0 Answers
[SOLVED]Problems loading the scene 1 Answer