public static void Move(this Transform transform, Vector3 target, float time)
{
if (time < 0) Debug.LogError("Time can't be negative");
var start = transform.position;
var deltaTime = 0f;
var thread = _updateThreads.CreateThread();
Observable.EveryUpdate().Subscribe(action =>
{
if (deltaTime >= 1)
{
transform.position = target;
_updateThreads.ClearThread(thread);
}
transform.position = Vector3.Lerp(start, target, deltaTime);
deltaTime += Time.deltaTime / time;
}).AddTo(thread);
}
public static void Move(this Transform transform, Vector3 target, float time, AnimationCurve curve)
{
if (time < 0) Debug.LogError("Time can't be negative");
if (curve == null) Debug.LogError("Curve is null");
var start = transform.position;
var deltaTime = 0f;
var thread = _updateThreads.CreateThread();
Observable.EveryUpdate().Subscribe(action =>
{
if (deltaTime >= 1)
{
transform.position = target;
_updateThreads.ClearThread(thread);
}
transform.position = Vector3.Lerp(start, target, curve.Evaluate(deltaTime));
deltaTime += Time.deltaTime / time;
}).AddTo(thread);
}
public static void Move(this Transform transform, Vector3 target, float time, AnimationCurve curve = null)
transform.position = Vector3.Lerp(start, target, curve != null ? curve.Evaluate(deltaTime) : deltaTime);