- Home /
Question by
Auralien · Feb 24, 2015 at 10:26 AM ·
animationunity 4.6animationcurve
Is it safe to use Evaluate for AnimationCurve in Update function?
I have a small script that calculates the player-opponent score ratio (like in some old-school fighter games). This ratio is being displayed on screen then with the help of new Image object introduce with Unity 4.6. I use it's fillAmount to set player points parts like that:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class TopBarController : MonoBehaviour {
public Image pointsBar;
private const float pointsBarUpdateTime = 1.5f;
private AnimationCurve curve;
public void UpdatePointsBar(int playerPoints, int opponentPoints) {
float oldValue = pointsBar.fillAmount;
float newValue = playerPoints + opponentPoints != 0 ? ((float)playerPoints / ((float)playerPoints + (float)opponentPoints)) : 0.5f;
curve = AnimationCurve.EaseInOut(Time.time, oldValue, Time.time + pointsBarUpdateTime, newValue);
}
void Update() {
pointsBar.fillAmount = curve.Evaluate(Time.time);
}
}
UpdatePointsBar is being called from some other script at runtime on each points update.
The question is if it is safe to use curve.Evaluate(Time.time); in Update function the way I use it? Does this affect performance a lot?
Comment
Your answer