Search Unity

Click Screen To Play And Start Game?

Discussion in '2D' started by Dogg, Jul 22, 2014.

  1. Dogg

    Dogg

    Joined:
    Mar 5, 2014
    Posts:
    203
    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.
     
    WhateverWhenever and eneskoto like this.
  2. cbothra

    cbothra

    Joined:
    Mar 14, 2014
    Posts:
    125
    For this you need to add an Input.GetMouseButtonDown(0) in the update method.
     
  3. Dogg

    Dogg

    Joined:
    Mar 5, 2014
    Posts:
    203
    I thought something like that, thanks but how would I get it to pause? Put Time.timeScale = 0; somewhere?
     
  4. cbothra

    cbothra

    Joined:
    Mar 14, 2014
    Posts:
    125
    Am not able to understand, what you exactly mean by pause here. Could you please elaborate it furthermore?
     
  5. Vitor_r

    Vitor_r

    Joined:
    May 23, 2013
    Posts:
    93
    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.
     
  6. Pyrian

    Pyrian

    Joined:
    Mar 27, 2014
    Posts:
    301
    I'm curious what your pause button does? Vitor_r's suggestion above should work.
     
  7. Dogg

    Dogg

    Joined:
    Mar 5, 2014
    Posts:
    203
    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.
     
  8. Dogg

    Dogg

    Joined:
    Mar 5, 2014
    Posts:
    203
    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:

    Code (CSharp):
    1.  
    2. public GUISkin myskin;
    3.    
    4.     private Rect windowRect;
    5.     private bool paused = false , waited = true;
    6.    
    7.     private string clicked = "";
    8.    
    9.     private void Start()
    10.     {
    11.         windowRect = new Rect(Screen.width /2 - 100, Screen.height /2 - 100, 200, 200);
    12.     }
    13.    
    14.     private void waiting()
    15.     {
    16.         waited = true;
    17.     }
    18.    
    19.     private void Update()
    20.     {
    21.         if (waited)
    22.             if (Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.P))
    23.         {
    24.             if (paused)
    25.                 paused = false;
    26.             else
    27.                 paused = true;
    28.            
    29.             waited = false;
    30.             Invoke("waiting",0.3f);
    31.         }
    32.        
    33.         if (paused)
    34.             Time.timeScale = 0;
    35.         else
    36.             Time.timeScale = 1;
    37.        
    38.     }
    39.    
    40.     private void OnGUI()
    41.     {
    42.         if (paused)
    43.             windowRect = GUI.Window (0, windowRect, windowFunc, "Pause Menu");
    44.        
    45.     }
    46.  
    47.     private void windowFunc(int id)
    48.     {
    49.         if (GUILayout.Button ("Resume")) {
    50.             paused = false;
    51.         }
    52.         GUILayout.BeginHorizontal ();
    53.         if (GUILayout.Button ("Options")) {
    54.            
    55.         }
    56.         if (GUILayout.Button ("Quit")) {
    57.             Application.LoadLevel ("MainMenuScene");
    58.         }
    59.         GUILayout.EndHorizontal ();
    60.        
    61.        
    62.     }
    63. }
    64.  
     
    Last edited: Jul 23, 2014
  9. Dogg

    Dogg

    Joined:
    Mar 5, 2014
    Posts:
    203
    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.
     
  10. Pyrian

    Pyrian

    Joined:
    Mar 27, 2014
    Posts:
    301
    Well, it certainly works for me, that's exactly what I'm doing:

    Code (csharp):
    1. void Start () {
    2.     MyState = GameStates.Splash;
    3.     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.
     
  11. Dogg

    Dogg

    Joined:
    Mar 5, 2014
    Posts:
    203
    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.
     
  12. Dogg

    Dogg

    Joined:
    Mar 5, 2014
    Posts:
    203
    Never mind it does now pause on start. I guess I had to reload Unity because it wasn't working before that.
     
  13. Dogg

    Dogg

    Joined:
    Mar 5, 2014
    Posts:
    203
    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.
     
  14. Deleted User

    Deleted User

    Guest

    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.