Skip to content

Instantly share code, notes, and snippets.

@Raziel619
Created September 14, 2019 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raziel619/825033b1d058e73f7f7f13402e39109c to your computer and use it in GitHub Desktop.
Save Raziel619/825033b1d058e73f7f7f13402e39109c to your computer and use it in GitHub Desktop.
Functions in FloatingText.cs - Medium Post
public void RunMessage(string msg, Color color)
{
if((msg == string.Empty) || (msg == null))
{
return;
}
_queue.Enqueue(new MessageWithColor(msg, color));
if((_queue.Count == 1) && (!_isDequeuing))
{
StartCoroutine(DequeueMessages());
_isDequeuing = true;
}
}
public void RunMessage(MessageWithColor mwc)
{
RunMessage(mwc.message, mwc.color);
}
private IEnumerator DequeueMessages()
{
//Dequeuing Items
while (_queue.Count > 0)
{
GameObject tmp = Instantiate(slideMsg, new Vector2(-3000, 0), Quaternion.identity, transform);
//Getting FloatingTextSingle component from prefab to calculate pause duration as well as set values
FloatingTextSingle fts = tmp.GetComponent<FloatingTextSingle>();
MessageWithColor mwc = _queue.Dequeue();
fts.SetValues(mwc.message, mwc.color);
yield return new WaitForSeconds(fts.pauseTime * (fts.positions.Length - 1) * 0.3f);
}
_isDequeuing = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment