Quaternion and Vector3 transfomation Math hi I have made and AI for my enemies which works perfectly but a particular section of code is repetitive and I feel that it can be optimised

void ChangeDirection()
    {
        if (movement == Vector3.left)
            transformModel.rotation = Quaternion.Euler(0, 270, 0);
        else if (movement == Vector3.right)
            transformModel.rotation = Quaternion.Euler(0, 90, 0);
        else if (movement == Vector3.back)
            transformModel.rotation = Quaternion.Euler(0, 180, 0);
        else if (movement == Vector3.forward)
            transformModel.rotation = Quaternion.Euler(0, 0, 0);
    }


the enemy will be in a tight corridor where only the following movements are possible i.e enemy can only move the vector3. right, left, back and forward. thus the code works without any issues,
however, the code is repetitive and I want the enemy to move in whichever its movement vector will be.

here is the rest my code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyMovement2 : MonoBehaviour
{
    public float speed;
    public Vector3 movement;
    public Animator animator;
    private GameObject gameManager;

    void Start()
    {

        movement = Vector3.back;
        gameManager = GameObject.FindWithTag("GameController");


    }
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Wall")
        {

            CorrectPosition(new Vector3(1, 1, 1));
            movement = Vector3.zero;

        }
    }

    public Transform transformModel;
    void ChangeDirection()
    {
        if (movement == Vector3.left)
            transformModel.rotation = Quaternion.Euler(0, 270, 0);
        else if (movement == Vector3.right)
            transformModel.rotation = Quaternion.Euler(0, 90, 0);
        else if (movement == Vector3.back)
            transformModel.rotation = Quaternion.Euler(0, 180, 0);
        else if (movement == Vector3.forward)
            transformModel.rotation = Quaternion.Euler(0, 0, 0);
    }
    void CorrectPosition(Vector3 CorrectPositionOF)
    {
        Vector3 posNow = transform.position;
        if (CorrectPositionOF.x == 1)
            posNow.x = Mathf.RoundToInt(gameObject.transform.position.x);
        if (CorrectPositionOF.y == 1)
            posNow.y = Mathf.RoundToInt(gameObject.transform.position.y);
        if (CorrectPositionOF.z == 1)
            posNow.z = Mathf.RoundToInt(gameObject.transform.position.z);
        transform.position = posNow;
    }
    public LayerMask whatIsWall;
    private Vector3[] direction = { Vector3.left, Vector3.forward, Vector3.back, Vector3.right };
    void FixedUpdate()
    {
        GetComponent&lt;Rigidbody&gt;().velocity = movement * speed;
        animator.SetFloat("runningSpeed", GetComponent&lt;Rigidbody&gt;().velocity.magnitude);
        for (int i = 0; i &lt; direction.Length; i++)
        {
            RaycastHit hit;
            if (Physics.Raycast(transform.position, direction[i], out hit, 18, 0 &lt;&lt; 11 | 1 &lt;&lt; 8 | 1 &lt;&lt; 9)
                &amp;&amp; hit.collider.gameObject.tag == "Player"
                &amp;&amp; movement == Vector3.zero)
            {
                movement = direction[i];
                ChangeDirection();
                return;
            }
        }


    }
}
```
If you want DRY the KISS way, I suggest substituting the if-chain..


if (movement == Vector3.left)
    transformModel.rotation = Quaternion.Euler(0, 270, 0);
else if (movement == Vector3.right)
    transformModel.rotation = Quaternion.Euler(0, 90, 0);
else if (movement == Vector3.back)
    transformModel.rotation = Quaternion.Euler(0, 180, 0);
else if (movement == Vector3.forward)
    transformModel.rotation = Quaternion.Euler(0, 0, 0);



..with a lookup map:

var rotationsEulerY = new Dictionary&lt;Vector3, int&gt;
{
    {Vector3.left, 270}, {Vector3.right, 90}, {Vector3.back, 180}, {Vector3.forward, 0}
};

void ChangeDirection()
{
    transformModel.rotation = Quaternion.Euler(0, rotationsEulerY[movement], 0);
}


You could do something similar for CorrectPosition using a predefined map of guard conditions and assignor actions.