using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DT : MonoBehaviour
{
public float beginValue, endValue;
public float beginTime, times;
public Action<float> action;
public Action onComplete;
public static DT To(Action<float> action, float beginvalue, float endvalue, float time)
{
GameObject go = new GameObject("DT");
DT dt = go.AddComponent<DT>();
dt.beginValue = beginvalue;
dt.endValue = endvalue;
dt.times = time;
dt.action = action;
dt.beginTime = Time.time;
return dt;
}
public DT OnComplete(Action action)
{
onComplete = action;
return this;
}
// Update is called once per frame
void Update()
{
if (Time.time - beginTime <= times)
{
float value = Mathf.Lerp(beginValue, endValue, (Time.time - beginTime) / times);
action?.Invoke(value);
}
else
{
onComplete?.Invoke();
Destroy(gameObject);
}
}
}
标签:float,DoTween,DT,Action,Unity,手写,action,dt,public
From: https://blog.csdn.net/djrjnfjdjejb/article/details/139868074