-2

this is my code

   void Start () {  
    GetComponent<SpriteRenderer>().enabled = false;
    animator = transform.GetComponentInChildren<Animator>();
    if (animator == null) {
        Debug.LogError("Didn't find animator");
    }
}
}








    GetComponent<Rigidbody2D>().AddForce(Vector2.right * forwardSpeed);

    if (didFlap) {

        GetComponent<Rigidbody2D>().AddForce (Vector2.up * flapSpeed);
        animator.SetTrigger("Doflap");

        didFlap = false;
        time = 0;
    }

// Do graphics & input update
void Update(){
    if(Input.GetKeyDown(KeyCode.Space) || (Input.GetMouseButtonDown(0))){

        didFlap=true;

    }





}

public void TakeDamage(float tim) {
    Application.LoadLevel(Application.loadedLevel);

}
// Do physics engine update
void FixedUpdate () {

    if (dead) {

        Time.timeScale = 0;
        GetComponent<SpriteRenderer>().enabled = true;



        if(Time.timeScale == 0 && (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0))){
            Application.LoadLevel(Application.loadedLevel);

here when i give the line(Application.LoadLevel(Application.loadedLevel);) with out if the game restarts.but when i give inside the if its not working..on the game dead i set the Time.timeScale to 0,and a restart button appears on the screen.on a touch again i need to restart.but when i gave the code for restart inside the if its not working,when i give it with out if the game suddenly restarts after dead with out giving a space to click the restart button. i need to restart on the button click

    }
}

void OnCollisionEnter2D(Collision2D collision){

    animator.SetTrigger("Death");
    dead = true;

}
}
Backs
  • 24,430
  • 5
  • 58
  • 85
robin
  • 1
  • 2

1 Answers1

0

When you set the TimeScale to 0, your Inputs will also stop working as they are dependant on the actual Time ;-) You could however still use the Input.GetAxisRaw to achieve similar goal. As it is not depending on the TimeScale.

But a better solution is to just add a UI Button that are available in unity 4.6+, using their new built in UI.

Zerratar
  • 1,229
  • 11
  • 10