private IEnumerator CanonBackToDock(VirusVice6MiniCanon canon) { int index = _miniCanons.IndexOf(canon); bool isLerp = false; float lerpDelta = 0; while (true) { Vector3 targetPos = _dockPoss[index].position; if (!isLerp) { float delta = Time.deltaTime * 10; Vector3 distance = targetPos - canon.transform.position; Vector3 offsetDir = distance.normalized - canon.transform.right; canon.transform.right = (canon.transform.right * 5f + offsetDir * 2).normalized; float dd = Vector3.Dot(canon.transform.right, distance); if (dd * dd < delta * delta && distance.sqrMagnitude < delta * delta) { isLerp = true; canon.transform.right = _dockPoss[index].right; canon.TurnOffWings(); } canon.transform.position += canon.transform.right * delta; } else { lerpDelta += Time.deltaTime; if (lerpDelta >= 1) { lerpDelta = 1; canon.transform.parent = index >= 2 ? _rightWing : _leftWing; } canon.transform.right = Vector3.LerpUnclamped(canon.transform.right, _dockPoss[index].right, Time.deltaTime); canon.transform.position = Vector3.LerpUnclamped(canon.transform.position, targetPos, lerpDelta); if (lerpDelta >= 1) { _backCount++; if (_backCount == 4) { _isEnergyFull = false; Initi(); } yield break; } } yield return(null); } }
public void BackToDock(VirusVice6MiniCanon canon) { StartCoroutine(CanonBackToDock(canon)); }