- Home /
This question was
closed Apr 29, 2018 at 11:01 PM by
doctoct for the following reason:
The question is answered, right answer was accepted
Question by
doctoct · Apr 23, 2018 at 04:53 AM ·
scripting problemprogramminghelloworld
Trying to disable the Script below on trigger or the closest thing
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class PauseGame : MonoBehaviour
{
public Transform canvas;
public Transform Player;
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
Pause();
}
}
}
public void Pause()
{
if (canvas.gameObject.activeInHierarchy == false)
{
canvas.gameObject.SetActive(true);
Time.timeScale = 0;
Player.GetComponent<FirstPersonController>().enabled = false;
}
else
{
canvas.gameObject.SetActive(false);
Time.timeScale = 1;
Player.GetComponent<FirstPersonController>().enabled = true;
}
}
}
I need to disable this Script when I hit a trigger so I can no longer pause at the game end menu. I've tried destroying the object and that gets rid of my Canvas which is great but my Time.timeScale = 1 still activates when pressing Esc. Anything yall can think of is greatly appreciated!!!
Comment
using UnityEngine;
using UnityEngine.UI;
using UnityStandardAssets.Characters.FirstPerson;
public class CursorVis : $$anonymous$$onoBehaviour
{
public Transform canvas;
public Transform Player;
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
canvas.gameObject.SetActive(true);
Player.GetComponent<FirstPersonController>().enabled = false;
Time.timeScale = 0;
Cursor.lockState = CursorLock$$anonymous$$ode.None;
Cursor.visible = true;
}
}
}
"This is my trigger object. I'd like to add the solution into this script" They're both using separate Canvas's. The first script activates my pause menu on esc. The second is my trigger to show my end game Canvas.
It seems like you are over-complicating things here. Just use boolean values for checking things like this. So if game end menu is enabled, set the bool value for pausing accordingly and pausing is not possible then.
ex:
if(canPause) { // Pause } else { // Cannot Pause }