Advertisement
Cookie042

Untitled

Sep 21st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using UnityEngine;
  4.  
  5. public class rectDisplay : MonoBehaviour
  6. {
  7.  
  8.     // Start is called before the first frame update
  9.     async void Start()
  10.     {
  11.  
  12.         List<Task> tasks = new List<Task>();
  13.  
  14.         tasks.AddRange(new[]
  15.         {
  16.             lerp(gameObject, Vector3.right, 1),
  17.             lerp(gameObject, Vector3.right, 1),
  18.             lerp(gameObject, Vector3.right, 1),
  19.             lerp(gameObject, Vector3.right, 1)
  20.         });
  21.  
  22.         await new WaitForUpdate();
  23.  
  24.         await Task.WhenAll(tasks);
  25.  
  26.         Debug.Log("done!");
  27.  
  28.     }
  29.  
  30.     void Update()
  31.     {
  32.         Debug.Log("updating");    
  33.     }
  34.  
  35.  
  36.     async Task lerp (GameObject go, Vector3 movementVector, float movementDuration)
  37.     {
  38.         float time = 0f;
  39.         float lastTime = 0f;
  40.         do
  41.         {
  42.             time += Time.deltaTime / movementDuration;
  43.             var dt = (time < 1) ? time - lastTime : 1 - lastTime;
  44.             lastTime = time;
  45.  
  46.             go.transform.position += dt * movementVector;
  47.  
  48.             await new WaitForUpdate();
  49.  
  50.         } while (time < 1);
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement