UITweenPostion.cs 691 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class UITweenPostion : MonoBehaviour
  6. {
  7. public float speed = 1;
  8. public float time = 1;
  9. public Vector3 startPos;
  10. public Vector3 endPos;
  11. public bool isLoop = false;
  12. public void Start()
  13. {
  14. StartCoroutine(Move());
  15. }
  16. IEnumerator Move()
  17. {
  18. float t = 0;
  19. while (t < time)
  20. {
  21. t += Time.deltaTime * speed;
  22. transform.position = Vector3.Lerp(startPos, endPos, t / time);
  23. yield return null;
  24. }
  25. if (isLoop)
  26. {
  27. StartCoroutine(Move());
  28. }
  29. }
  30. }