Hello!
I’m working on a Pause menu using (Time.timeScale) and I’ve come across this annoying thing that I can’t fix.
My game relies heavily on mouse button presses that activate different powers depending on the button. Each time it registers a button press, there’s a quick UI image fade-out to let the player know what power he’s using.
These powers last for as long as the player keeps said mouse button pressed, by the way.
Here’s the problem: I’ve noticed that keeping a button pressed while in the Pause menu and resuming the game (button still pressed) makes the UI image appear on screen, but it doesn’t fade out. It just stays there until I let go of the button, and then it’s instantly disabled.
Any idea on how to fix this? Thanks a lot!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Blink_Icon_1 : MonoBehaviour
{
[SerializeField] private Image eyes_left;
void Update()
{
if (Input.GetMouseButton(0))
eyes_left.enabled = true;
else
{
eyes_left.enabled = false;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UI_Fade_Out : MonoBehaviour {
CanvasRenderer rend;
void Start () {
rend = GetComponent<CanvasRenderer>();
}
IEnumerator FadeOut ()
{
for (float f = 1f; f > -0.45f; f -= 0.45f)
{
Color c = rend.GetColor();
c.a = f;
rend.SetColor(c);
yield return new WaitForSeconds(0.05f);
}
}
public void Update()
{
if (Input.GetMouseButtonDown(0))
StartCoroutine("FadeOut");
}
}