Player Rotation around Y axis change color

Hello This is Mahsa ,

I have a player that moves with joystick, and I check the player rotation in updated if player reached like 20 degree change player color but the I when I’m rotating it won’t stay on that changing color, when i’m rotating i want to stay in that color
here’s my code :slight_smile:

    [SerializeField] private Transform rotateBody;
    [SerializeField] private float rotateAngle = 20f;
    [SerializeField] private PlayerAnimationManager playerAnimation;

    private float startPos;
    private float currentPos;

    [SerializeField] private SkinnedMeshRenderer skin;
    [SerializeField] private Material turnMaterial;
    private Color startColor;
    private int turCounter;


    private void Start()
    {
        startPos = rotateBody.transform.rotation.eulerAngles.y;
        startColor = skin.material.color;
    }

    private void Update()
    {
        currentPos = rotateBody.transform.rotation.eulerAngles.y;

      
        
        if (Mathf.Abs(currentPos - startPos) > rotateAngle)
        {
            startPos = rotateBody.transform.rotation.eulerAngles.y;
            
            turCounter++;

            StartCoroutine(TurnManager());
            playerAnimation.StartCoroutine(playerAnimation.LeftMoveAnimation());
            playerAnimation.StartCoroutine(playerAnimation.RightMoveAnimation());

        }
    }

    private IEnumerator TurnManager()
    {
        StartCoroutine(ColorChanger(turnMaterial.color));
        yield return new WaitForSeconds(6 + turCounter);
        StartCoroutine(ColorChanger(startColor));
    }

    private IEnumerator ColorChanger(Color nextColor)
    {
        float timer = 0;
        float duration = 1f;

        while (timer < duration)
        {
            timer = Mathf.Min(timer + Time.deltaTime, duration);
            float t = timer / duration;

            var newColor = Color.Lerp(skin.material.color, nextColor, t);
            skin.material.color = newColor;

            yield return new WaitForEndOfFrame();
        }

        if (skin.material.color == nextColor)
        {
            turCounter = 0;
        }
    }