Skip to content

Instantly share code, notes, and snippets.

@Raziel619
Created September 14, 2019 19:48
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/a6d082ea6ec90c2536dbe6f1a9ead584 to your computer and use it in GitHub Desktop.
Save Raziel619/a6d082ea6ec90c2536dbe6f1a9ead584 to your computer and use it in GitHub Desktop.
Functions in FloatingTextSingle.cs - Medium Post
public void Start()
{
if(positions != null)
{
_rectTransform = GetComponent<RectTransform>();
_nextDestination = positions[0];
_iterator = 0;
}
else
{
Destroy(gameObject);
}
}
// Update is called once per frame
public void FixedUpdate()
{
//_paused is toggled in coroutine PauseForTime()
if (_paused)
{
return;
}
_rectTransform.localPosition = Vector2.Lerp(_rectTransform.localPosition, _nextDestination, movSpeed);
if(Vector2.Distance(_rectTransform.localPosition, _nextDestination) <= 0.3f)
{
//Setting new destination from array, exiting and destroying if at end of array
++_iterator;
if(_iterator >= positions.Length)
{
Destroy(gameObject);
}
else
{
_nextDestination = positions[_iterator];
}
}
}
public void SetValues(string msg, Color color)
{
mainText.text = msg;
mainColor.color = color;
}
private IEnumerator PauseForTime()
{
_paused = true;
yield return new WaitForSeconds(pauseTime);
_paused = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment