Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using UnityEngine;
- public class rectDisplay : MonoBehaviour
- {
- // Start is called before the first frame update
- async void Start()
- {
- List<Task> tasks = new List<Task>();
- tasks.AddRange(new[]
- {
- lerp(gameObject, Vector3.right, 1),
- lerp(gameObject, Vector3.right, 1),
- lerp(gameObject, Vector3.right, 1),
- lerp(gameObject, Vector3.right, 1)
- });
- await new WaitForUpdate();
- await Task.WhenAll(tasks);
- Debug.Log("done!");
- }
- void Update()
- {
- Debug.Log("updating");
- }
- async Task lerp (GameObject go, Vector3 movementVector, float movementDuration)
- {
- float time = 0f;
- float lastTime = 0f;
- do
- {
- time += Time.deltaTime / movementDuration;
- var dt = (time < 1) ? time - lastTime : 1 - lastTime;
- lastTime = time;
- go.transform.position += dt * movementVector;
- await new WaitForUpdate();
- } while (time < 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement