Created
September 14, 2019 19:48
-
-
Save Raziel619/a6d082ea6ec90c2536dbe6f1a9ead584 to your computer and use it in GitHub Desktop.
Functions in FloatingTextSingle.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 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