Files

39 lines
992 B
C#

using System;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace Animations
{
public class AsyncTween : MonoBehaviour
{
private void Start()
{
Animate();
}
private async UniTask Animate()
{
float time = 0.0f;
// move
while (time < 1.0f)
{
transform.position = Vector3.Lerp(Vector3.zero, Vector3.forward * 5.0f, time);
// await Task.Delay(100);
await UniTask.DelayFrame(1);
time += Time.deltaTime;
}
// scale
time = 0.0f;
while (time < 1.0f)
{
transform.localScale = Vector3.Lerp(Vector3.one, Vector3.one * 2.0f, time);
// await Task.Delay(100);
await UniTask.DelayFrame(1);
time += Time.deltaTime;
}
}
}
}