Question by
Gundi · Aug 14, 2017 at 06:55 AM ·
gameobjecttimescalemouseovergetmousebutton
Pause my game with a game object!
Hello, I would like my game to pause when clicking on a game object ( not gui button).
I've tryed tons of things but nothing worked.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pause : MonoBehaviour {
public bool paused;
// Use this for initialization
void Start () {
paused = false;
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonUp(0)){
paused = !paused;
}
if (paused) {
Time.timeScale = 0;
AudioListener.pause = true;
}
else if (!paused) {
Time.timeScale = 1;
AudioListener.pause = false;
}
}
}
Can somoene help me out please? He would be my god!
Comment