- Home /
UI Image disappear
Hi! I recently started learning Unity and I have a problem. In my game when I trigger an object a gate opens, so after I trigger the object a message appears with "Gate is Open" and the game pauses. I want to make the game resume and the message disappear by pressing Space, but whatever i try it doesn't work. I've read some forums and I guess it is because I use the OnTriggerEnter. Please can you help me? This is my code: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class destroy : MonoBehaviour { public GameObject gate; public GameObject orb; public GameObject gateopen; bool isPaused = false;
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
Destroy(gate, 2f);
gateopen.SetActive(true);
orb.SetActive(false);
Time.timeScale = 0f;
isPaused = true;
}
}
void OnTriggerStay(Collider other)
{
if (other.tag == "Player")
if (Input.GetKeyDown(KeyCode.Space))
{
gateopen.SetActive(false);
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
if (isPaused)
{
gateopen.SetActive(false);
Time.timeScale = 1f;
}
}
}
}
Your answer
Follow this Question
Related Questions
Trigger Script Not Firing 4 Answers
Making a UI.Button put text into a InputField 1 Answer
Missing or garbled text in UI.Text 0 Answers
UI Text not showing up in play mode 0 Answers
Fading a Text component with Shadow and Outline causes a problem 2 Answers