How to trigger game pause with clicking object instead of keycode?
Hello. I hope you guys can help me out because I'm very new to this :( So I've been trying to follow a hidden object game tutorials on youtube >> This one
It's about making a game pause menu. The thing is, the script provided is to trigger the pause menu with keycode, is there any way to change this so I can trigger the pause menu with clicking the pause image (gameobject)? I know about the OnMouseDown thing but not sure how to use it in the script below...
Here's the script for the tracking clicks :
using UnityEngine; using System.Collections;
public class trackingclicks : MonoBehaviour {
public static int totalclicks=0;
public KeyCode mouseclick;
public KeyCode pauseClick;
public static string gamePause = "n";
public Transform pMenuObj;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(pauseClick))
{
gamePause = "y";
pMenuObj.GetComponent<Transform>().position = new Vector2(0, 1);
}
if (gamePause == "n")
{
pMenuObj.GetComponent<Transform>().position = new Vector2(-20, 1);
}
if (Input.GetKeyDown (mouseclick))
{
totalclicks += 1;
}
if (totalclicks >= 5)
{
Debug.Log ("FAIL!!!");
totalclicks = 0;
}
}
}
Thanks in advance!
Your answer
Follow this Question
Related Questions
Disable mouse click on gameObject 1 Answer
On Off sound 0 Answers
I'd like my object to be active only when space key is NOT pressed 1 Answer
if (Input.GetKey (KeyCode.Escape)) Won't Work. 0 Answers
On-click and trigger animation c# 1 Answer