Prefab C# : Level Restart Alert problem : Android

Hello , I’m a newbie in programming C# I am developing a game , I created a prefab of a picture alert which will appear when the user has failed to complete the stage it says “Tap to restart level” the function i want for it is when the picture is tapped the game will restart its level now the problem is whenever the user taps anywhere on the screen the game will restart even if the game is not failed.

Here’s the code I created, theres something wrong with it .
Thanks for taking your time seeing this .

using UnityEngine;
using System.Collections;

public class Restart : MonoBehaviour
{
    void Update()
    {
        if (Input.GetButton("Fire1"))
        {
            Reload();
        }
    }

    void Reload()
    {
        Application.LoadLevel(Application.loadedLevel);
    }
}

Hello!

The problem with your script is that it is constantly listening for clicks on the button assigned to “Fire1”, which seems to be your mouse button, and when a click is triggered then the function Reload() is executed.

I recommend that you take a look into Unity’s UI system and try to build it with that, there are tons of resources and tutorials on this subject. Check out https://unity3d.com/learn/tutorials/modules/beginner/ui/ui-button for information about how to use the UI Button. Then you can assign your reload function so it is called when the button is pressed.

you have to test if the user has failed to complete the stage & then test button “'Fire1” is pressed then load level :

 void Update()
 {
     if(playerfaild) // what ever how you decide the player faild
     {
         if (Input.GetButton("Fire1"))
         Reload();
     }
 }