So this is my simple ADS script but there is a problem, I cant lerp back from ADS gun position to Normal gun position I tried many different ways but the Editor always freezes I simply cant get it to work

If anyone knows what Iâam doing wrong please tell me.
(Problem at coroutine âReturnToNormalPosâ)

using UnityEngine;
using System.Collections;
public class PlayerADS : MonoBehaviour
{
public Vector3 ADSpos;
public Vector3 NormalPos;
public Camera PlayerCam;
public float Speed;
void Start()
{
PlayerCam = gameObject.GetComponentInParent<Camera>();
}
void Update()
{
if (Input.GetMouseButton(1))
{
transform.localPosition = Vector3.Lerp(transform.localPosition, ADSpos, Speed * Time.deltaTime);
if (PlayerCam.fieldOfView > 75)
{
PlayerCam.fieldOfView = Mathf.Lerp(PlayerCam.fieldOfView, PlayerCam.fieldOfView - 10, Speed * Time.deltaTime);
}
}
if (Input.GetMouseButtonUp(1))
{
StartCoroutine("ReturnToNormalPos");
}
}
IEnumerator ReturnToNormalPos()
{
while (transform.localPosition != NormalPos)
{
transform.localPosition = Vector3.Lerp(transform.localPosition, NormalPos, Speed * Time.deltaTime);
if (PlayerCam.fieldOfView < 75)
{
PlayerCam.fieldOfView = Mathf.Lerp(PlayerCam.fieldOfView, PlayerCam.fieldOfView + 10, Speed * Time.deltaTime);
}
}
yield return null;
}
}

yield return null should be inside the while loop for starters. Secondly, youâre using Lerp incorrectly; the third parameter is âpercentage of completionâ not a speed or distance. Thirdly, youâre not checking if the coroutine is already running before starting a new one so a user could click rapidly and spin up multiple coroutines resulting in odd behavior. Lastly, directly comparing the equality of two vectors isnât advised due to floating point precision issues; instead check if the distance between them is very small.

Just to be clear:
If your checking if 2 Vector3 are âequalâ, the > should be < (Your making sure the 2 Vectorâs distance is smaller than some small number.

@LiterallyJeff if statement is if they are != (not equal)

His condition is saying while they are not together, continue the loop.

My example continues the loop while the distance is greater than approximately 0. So until they are within 0.01 units of each other, they will continue to get closer.

Indeed it does but Iâve run into issues with loops like that never completing before so Iâm always wary. And Unityâs equality override is BS so I try to pretend it doesnât exist