Created
September 14, 2019 19:51
-
-
Save Raziel619/825033b1d058e73f7f7f13402e39109c to your computer and use it in GitHub Desktop.
Functions in FloatingText.cs - Medium Post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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