- Home /
Opacity text freeze bug
So I have a checkpoint system which providing the player has the atleast 1 of an object then it will be able to activate a checkpoint. When discovering / activate checkpoints there will be a numerous amount of messages which will have their opacity fade in / out
However I have noticed a bug that shows up only when if a player activates a checkpoint.
When the player discovers a checkpoint it will display the message "Checkpoint discovered \n Press F to activate" if the player activates the checkpoint it will display the message "Checkpoint Activated"
Now what should happen is when the checkpoint discovered mesage appears it should fade out and the checkpoint activated message should fade in.
If the player presses the F button faster than the message fading out then it should fade out faster and fade in the activated message.
However instead if the player press the F button to activate checkpoint whilst the discovered checkpoint message is fading out then the checkpoint activated message will get stuck at the opacity level that checkpoint discovered message was stopped at and will then ignore all fade in / outs for all messages until a new checkpoint is discovered and then it will reset the opacity back to normal.
You can also see that if a message has been displayed such as "can't activate checkpoint again" or "checkpoint discovered" once it has been displayed it won't display any additional times (I want it to display additional times) but instead only the once.
See gif link below for bug (messages appear at top of image) http://im2.ezgif.com/tmp/ezgif.com-d83d3b3465.gif
Code for checkpoint system is below:
public static int _currentMatches = 3;
private float speed = 1f;
public bool inZone = false;
private bool triggered = false;
public Text matches_text;
public Text _HUD_Text;
public CanvasGroup canvasGroup = null;
public LevelManager levelManager;
void Start()
{
levelManager = FindObjectOfType<LevelManager>();
matches_text.text = "X " + _currentMatches;
_HUD_Text.text = " ";
}
void Update()
{
if (Input.GetKeyDown(KeyCode.F) && inZone && levelManager.currentCheckpoint != gameObject)
{
StopCoroutine("Opacity");
triggered = false;
if (_currentMatches >= 1)
{
levelManager.currentCheckpoint = gameObject;
gameObject.GetComponentInChildren<ParticleSystem>().Play();
gameObject.GetComponentInChildren<Light>().enabled = true;
_currentMatches--;
matches_text.text = "X " + _currentMatches;
StartCoroutine("Opacity");
_HUD_Text.text = "Checkpoint Activated";
}
else if (_currentMatches <= 0)
{ _currentMatches = 0; }
}
if (inZone && levelManager.currentCheckpoint != gameObject)
{
_HUD_Text.text = "Checkpoint Discovered \nPress F to activate";
StartCoroutine("Opacity");
}
if (!inZone && levelManager.currentCheckpoint != gameObject)
{
gameObject.GetComponentInChildren<ParticleSystem>().Stop();
gameObject.GetComponentInChildren<Light>().enabled = false;
}
if (inZone && levelManager.currentCheckpoint != gameObject && _currentMatches == 0)
{
_HUD_Text.text = "No Matches To Activate Checkpoint \nGo Find Some";
StartCoroutine("Opacity");
}
}
IEnumerator Opacity()
{
if (!triggered)
{
triggered = true;
if (canvasGroup.alpha == 1)
{
canvasGroup.alpha = 0;
}
yield return FadeIn();
yield return new WaitForSeconds(1f);
yield return FadeOut();
triggered = false;
}
}
IEnumerator FadeIn()
{
while (canvasGroup.alpha < 1)
{
canvasGroup.alpha += Time.deltaTime * speed;
yield return null;
}
}
IEnumerator FadeOut()
{
while (canvasGroup.alpha > 0)
{
canvasGroup.alpha -= Time.deltaTime * speed;
yield return null;
}
}
public void OnTriggerEnter(Collider other)
{
if (other.name == "Player")
{
inZone = true;
if (levelManager.currentCheckpoint == gameObject)
{
_HUD_Text.text = "Can't Activate Checkpoint Again";
StartCoroutine(Opacity());
}
}
}
public void OnTriggerExit(Collider other)
{
if (other.name == "Player")
{ inZone = false; }
}
public void AddMatches(int _matchesAmount)
{
_currentMatches += _matchesAmount;
matches_text.text = "X " + _currentMatches;
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
2D collisions in Unity 4.3? 1 Answer
Coins work in engine but not on phone 0 Answers
How to move an object over a distance in a direction? 2 Answers