0
\$\begingroup\$

When my character died it displays gameover and goes back to main menu, then if I clicked play I can see my character however I can't make it move anymore. Any suggestions?

For game over:

#pragma strict
import UnityEngine.UI;
private var StopGame: boolean=false;
private var showGUI: boolean=false;
var GUIstop: GameObject;
var StopMenu;

private var canvas : Canvas;

function Awake()
{
    canvas = GetComponent.<Canvas>();
    canvas.enabled = false;
}

function Update ()
{
    // If the player has run out of health...
    if(HealthControl.LOVES==0)
        Pause();
    //  }
}

public function Pause()
{
    canvas.enabled = !canvas.enabled;
    Time.timeScale = Time.timeScale == 0 ? 1 : 0;
    StopGame=true;
}

public function Quit()
{
    #if UNITY_EDITOR 
    EditorApplication.isPlaying = false;
    #else 
    Application.Quit();
    #endif
}

For character movement:

   function Update () {

       transform.rotation.z=0;

       if(Input.GetKey(KeyCode.UpArrow)){
           transform.position.y+=moveSpeed*Time.deltaTime;
       }
       else if(Input.GetKey(KeyCode.RightArrow)){
           transform.position.x+=moveSpeed*Time.deltaTime;
       }
\$\endgroup\$
1
\$\begingroup\$

It's hard to tell exactly what the problem could be, since there must be more scripts than just those two, but Time.timeScale has probably been set to 0. Time.deltaTime is affected by the Time Scale, so you'll need to ensure that you set it back to 1 when you resume the game. If you need a deltaTime unaffected by Time Scale, you can use Time.unscaledDeltaTime

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

It seems like you are stopping the character when he runs out of health on the update, maybe try increasing his health at the start method?

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.