using UnityEngine; using System.Collections; public class Test2DLocalMove : MonoBehaviour { //public Transform from; //public Transform to; public Vector3 mStart = Vector3.zero; public Vector3 mEnd = Vector3.zero; Vector3 center = Vector3.zero; private float mF1; private float mF2; private float mFloat = 0; bool isYes = false; public void Init(Vector3 start, Vector3 end) { this.mStart = start; this.mEnd = end; LogHelper.Log(this.mStart.ToString() + "/" + this.mEnd.ToString()); mF1 = Random.Range(-2.0f, 2.0f); mF2 = Random.Range(0.0f, 1.0f); isYes = true; // 弧线的中心 center = (mStart + mEnd) * 0.5f; } void Update() { if (isYes) { mFloat += Time.deltaTime*30000; // 向下移动中心,垂直于弧线 center -= new Vector3(mF2, mF1, 0); // 相对于中心在弧线上插值 Vector3 riseRelCenter = mStart - center; Vector3 setRelCenter = mEnd - center; transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, mFloat); transform.position += center; if (transform.position == mEnd) { isYes = false; StartCoroutine(Destroy()); } } } IEnumerator Destroy() { yield return new WaitForSeconds(0.2f); //Destroy(this.gameObject); } }