SHARE
TWEET

Untitled

a guest May 23rd, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class TransformUtils
  7. {
  8.     public static IEnumerator MoveTo(Vector3 from, Vector3 to, float duration,
  9.         Action<Vector3> onChange = null, Action onOver = null)
  10.     {
  11.         float t = 0;
  12.         Vector3 currentPosition = from;
  13.        
  14.         while (t < duration)
  15.         {
  16.             currentPosition = Vector3.Lerp(from, to, (t / duration));
  17.             if (onChange != null)
  18.                 onChange(currentPosition);
  19.             t += Time.deltaTime;
  20.             yield return null;
  21.         }
  22.         if (onChange != null)
  23.             onChange(to);
  24.  
  25.         if (onOver != null)
  26.             onOver();
  27.     }
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top