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;
}
}