using UnityEngine;
using UnityEngine.UI;
public class AniTest : MonoBehaviour
{
public AnimationCurve ac;
public Image image;
private void Start()
{
ac = CreateAnimationCurve();
}
private AnimationCurve CreateAnimationCurve()
{
Keyframe[] kf = new Keyframe[4];
kf[0] = new Keyframe(0, 0);
kf[1] = new Keyframe(1f, 1f);
kf[0].inTangent = 1.4f;
kf[0].outTangent = -1.4f;
kf[1].inTangent = -1.4f;
kf[1].outTangent = 1.4f;
AnimationCurve positionCurve = new AnimationCurve(kf);
positionCurve.preWrapMode = WrapMode.PingPong;
positionCurve.postWrapMode = WrapMode.PingPong;
positionCurve = new AnimationCurve(kf);
return positionCurve;
}
private void Update()
{
image.transform.localPosition = new Vector3(200f * ac.Evaluate(Time.time), image.transform.localPosition.y, image.transform.localPosition.z);
}
}