Click Screen To Play And Start Game?

Sorry if this has been posted before, but this is something I haven’t seen specifically yet. You know those games where you press play and it takes you to the game where it says tap/click to play, and the game begins after you tap/click the screen? Yeah I want to know how to do it. Well I do have a basic idea, however all attempts of getting it to work have failed, so I’ve come to you remarkable ladies and gentlemen for your help. So my idea is pause on start, have a script, GUI Texture, or something enable saying Tap/Click To Play, and then when input mouse is clicked, un-pause game and it pretty much starts from there.

Again I can’t get this idea to work, I can’t even get the game to pause on Start(which is a pain considering I have a pause button and it’s working, but not this). So does anyone want to share their ideas with me? I’d greatly appreciate it.

2 Likes

For this you need to add an Input.GetMouseButtonDown(0) in the update method.

I thought something like that, thanks but how would I get it to pause? Put Time.timeScale = 0; somewhere?

Am not able to understand, what you exactly mean by pause here. Could you please elaborate it furthermore?

If you want the game to be paused untill someone click or tap the screen. Use Time.timeScale = 0; on the Start() function. And then when someone click the screen u can set it back to 1 and the game will start playing.

I’m curious what your pause button does? Vitor_r’s suggestion above should work.

Like pause the game completely. Everything is stopped including the Player’s movement. Right now when I click play on Unity, it takes me to the game and the Player starts running(he always runs). So the game starts like that. What I want is when I press play on Unity or press start from the Main Menu scene, it takes me to the game like it does now except everything is paused(this includes music) and of course the Player is Idle, and it has a Sprite or something in the middle of the screen saying Click/Tap to play. So when you click/tap the game, it starts like it does now. The only example of a game doing this that i have right now is Flappy Bird. So yeah the reason I want to do this is because the game starts too fast and it might result in cheap deaths the first time someone plays it. As a gamer and programmer I cannot allow that.

My pause button stops the game completely when I press it. It is a GUI.Button and of course skin for looks. The only thing that it doesn’t stop is my music. Here’s part of my pause button script:

public GUISkin myskin;
   
    private Rect windowRect;
    private bool paused = false , waited = true;
   
    private string clicked = "";
   
    private void Start()
    {
        windowRect = new Rect(Screen.width /2 - 100, Screen.height /2 - 100, 200, 200);
    }
   
    private void waiting()
    {
        waited = true;
    }
   
    private void Update()
    {
        if (waited)
            if (Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.P))
        {
            if (paused)
                paused = false;
            else
                paused = true;
           
            waited = false;
            Invoke("waiting",0.3f);
        }
       
        if (paused)
            Time.timeScale = 0;
        else
            Time.timeScale = 1;
       
    }
   
    private void OnGUI()
    {
        if (paused)
            windowRect = GUI.Window (0, windowRect, windowFunc, "Pause Menu");
       
    }

    private void windowFunc(int id)
    {
        if (GUILayout.Button ("Resume")) {
            paused = false;
        }
        GUILayout.BeginHorizontal ();
        if (GUILayout.Button ("Options")) {
           
        }
        if (GUILayout.Button ("Quit")) {
            Application.LoadLevel ("MainMenuScene");
        }
        GUILayout.EndHorizontal ();
       
       
    }
}

Are you sure Time.timeScale = 0; works like that in the Start()? Because I tried that before and it didn’t pause the game. Though I only put Time.timeScale = 0 and did not set it back to 1.

Well, it certainly works for me, that’s exactly what I’m doing:

void Start () {
    MyState = GameStates.Splash;
    Time.timeScale = 0;

You want me to take a wild guess at this? Maybe you set the time scale to zero, but didn’t set your “paused” variable to true, and your very first Update call therefore set your timescale back to 1! Honestly, given the setup you’ve posted, you could just set “paused = true;” in your Start() function and your Update function will pause it in the first frame.

I took your advice on setting the paused = true in Start. It does not work sadly. It pauses the game only when I press escape, it doesn’t do it automatically. Did you see my post when I replied to cbothra? I asked this just to make sure you know what I want to accomplish. I’ve updated my pause script that I posted, I put the rest of the code at the end so you can see my full script. That script is used for when if someone is playing the game and they have to go to the restroom, they can pause during the game and come back later. So it’s completely different than what I want to do here. Here I want the game to pause on Start up, and when the Player is ready to play. he or she can click/tap the screen to begin.

Never mind it does now pause on start. I guess I had to reload Unity because it wasn’t working before that.

Actually no, the reason why it didn’t pause was because my other pause script was enabled. When I disable the pause script, the game pauses on start, but when I enable it, it doesn’t. This could be because they have almost the same coding as each other, and they also both turn Time.timeScale = 0; and back to 1. I’ll see if I can fix this.

Try creating a start scene and put in a game object with your background then use the code

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class GameControl : MonoBehaviour
{
void update { 
if(Input.GetMouseButtonDown(0)){
SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene().buildIndex);
SceneManager.LoadScene("Your_Scene");
}
}
}```
This is what I use.