TestMoveCure.cs 801 B

12345678910111213141516171819202122232425262728293031323334
  1. using UnityEngine;
  2. using System.Collections;
  3. public class TestMoveCure : MonoBehaviour {
  4. public GameObject t1; //开始位置
  5. public GameObject t2; //结束位置
  6. public float speed = 0;
  7. float mSpeed = 0;
  8. void Start()
  9. {
  10. Application.targetFrameRate = 60;
  11. }
  12. // Update is called once per frame
  13. void Update()
  14. {
  15. //两者中心点
  16. Vector3 center = (t1.transform.position + t2.transform.position) * 0.5f;
  17. center -= new Vector3(0, 1, 0);
  18. Vector3 start = t1.transform.position - center;
  19. Vector3 end = t2.transform.position - center;
  20. //弧形插值
  21. transform.position = Vector3.Slerp(start, end, mSpeed += Time.deltaTime * speed);
  22. transform.position += center;
  23. }
  24. }