optimize and clean or fix the logic in the c# script for unity below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

/// <summary>
/// A simple free camera to be added to a Unity game object.
/// 
/// Keys:
///	wasd / arrows	- movement
///	q/e 			- up/down (local space)
///	r/f 			- up/down (world space)
///	pageup/pagedown	- up/down (world space)
///	hold shift		- enable fast movement mode
///	right mouse  	- enable free look
///	mouse			- free look / rotation
///     
/// </summary>
public class FreeCam : MonoBehaviour
{
	public Animator Warn;
	public GameObject SimMGR;
	//public GameObject Manager;
	public bool CustomMode = false;
    /// <summary>
    /// Normal speed of camera movement.
    /// </summary>
    public float movementSpeed = 33f;

    /// <summary>
    /// Speed of camera movement when shift is held down,
    /// </summary>
    public float fastMovementSpeed = 233f;

    /// <summary>
    /// Sensitivity for free look.
    /// </summary>
    public float freeLookSensitivity = 3f;

    /// <summary>
    /// Amount to zoom the camera when using the mouse wheel.
    /// </summary>
    public float zoomSensitivity = 25f;

    /// <summary>
    /// Amount to zoom the camera when using the mouse wheel (fast mode).
    /// </summary>
    public float fastZoomSensitivity = 50f;

    /// <summary>
    /// Set to true when free looking (on right mouse button).
    /// </summary>
    private bool looking = false;

    void Update()
    {
        var fastMode = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
        var movementSpeed = fastMode ? this.fastMovementSpeed : this.movementSpeed;
		// DOWN.
        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        {
            transform.position = transform.position + (-transform.right * movementSpeed * Time.deltaTime);
			SimMGR.SetActive(false);
			Warn.Play("Warn_In");
		}
		// UP.
		if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.LeftArrow))
		{
			SimMGR.SetActive(true);
			Warn.Play("Warn_Out");
		}
		// DOWN.
		if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            transform.position = transform.position + (transform.right * movementSpeed * Time.deltaTime);
			SimMGR.SetActive(false);
			Warn.Play("Warn_In");
		}
		// UP.
		if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.RightArrow))
		{
			SimMGR.SetActive(true);
			Warn.Play("Warn_Out");
		}
		// DOWN.
		if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
        {
            transform.position = transform.position + (transform.forward * movementSpeed * Time.deltaTime);
			SimMGR.SetActive(false);
			Warn.Play("Warn_In");
		}
		// UP.
		if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.UpArrow))
		{
			SimMGR.SetActive(true);
			Warn.Play("Warn_Out");
		}
		// DOWN.
		if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
        {
            transform.position = transform.position + (-transform.forward * movementSpeed * Time.deltaTime);
			SimMGR.SetActive(false);
			Warn.Play("Warn_In");
		}
		// UP.
		if (Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.DownArrow))
		{
			SimMGR.SetActive(true);
			Warn.Play("Warn_Out");
		}
		// DOWN.
		if (Input.GetKey(KeyCode.Q))
        {
            transform.position = transform.position + (transform.up * movementSpeed * Time.deltaTime);
			SimMGR.SetActive(false);
			Warn.Play("Warn_In");
		}
		// UP.
		if (Input.GetKey(KeyCode.Q))
		{
			SimMGR.SetActive(true);
			Warn.Play("Warn_Out");
		}
		// DOWN.
		if (Input.GetKey(KeyCode.E))
        {
            transform.position = transform.position + (-transform.up * movementSpeed * Time.deltaTime);
			SimMGR.SetActive(false);
			Warn.Play("Warn_In");
		}
		// UP.
		if (Input.GetKeyUp(KeyCode.E))
		{
			SimMGR.SetActive(true);
			Warn.Play("Warn_Out");
		}
		// DOWN.
		if (Input.GetKey(KeyCode.R) || Input.GetKey(KeyCode.PageUp))
        {
            transform.position = transform.position + (Vector3.up * movementSpeed * Time.deltaTime);
			SimMGR.SetActive(false);
			Warn.Play("Warn_In");
		}
		// UP.
		if (Input.GetKeyUp(KeyCode.R) || Input.GetKeyUp(KeyCode.PageUp))
		{
			SimMGR.SetActive(true);
			Warn.Play("Warn_Out");
		}
		// DOWN.
		if (Input.GetKey(KeyCode.F) || Input.GetKey(KeyCode.PageDown))
        {
            transform.position = transform.position + (-Vector3.up * movementSpeed * Time.deltaTime);
			SimMGR.SetActive(false);
			Warn.Play("Warn_In");
		}
		// UP.
		if (Input.GetKeyUp(KeyCode.F) || Input.GetKeyUp(KeyCode.PageDown))
		{
			SimMGR.SetActive(true);
			Warn.Play("Warn_Out");
		}

		if (looking)
        {
            float newRotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * freeLookSensitivity;
            float newRotationY = transform.localEulerAngles.x - Input.GetAxis("Mouse Y") * freeLookSensitivity;
            transform.localEulerAngles = new Vector3(newRotationY, newRotationX, 0f);
        }

        float axis = Input.GetAxis("Mouse ScrollWheel");
        if (axis != 0)
        {
            var zoomSensitivity = fastMode ? this.fastZoomSensitivity : this.zoomSensitivity;
            transform.position = transform.position + transform.forward * axis * zoomSensitivity;
        }
		if(CustomMode == false)
		{
			if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.LeftAlt))
			{
				SimMGR.SetActive(false);
				Warn.Play("Warn_In");
				StartLooking();
			}
			else if (Input.GetKeyUp(KeyCode.Space) || Input.GetKeyUp(KeyCode.LeftAlt))
			{
				StopLooking();
			}
			if (Input.GetKeyUp(KeyCode.Space) || Input.GetKeyUp(KeyCode.LeftAlt))
			{
				SimMGR.SetActive(true);
				Warn.Play("Warn_Out");
			}
		}
		if(CustomMode == true)
		{
			if (Input.GetKeyDown(KeyCode.Mouse2))
			{
				StartLooking();
			}
			else if (Input.GetKeyUp(KeyCode.Mouse2))
			{
				StopLooking();
			}
		}
    }

    void OnDisable()
    {
        StopLooking();
    }

    /// <summary>
    /// Enable free looking.
    /// </summary>
    public void StartLooking()
    {
        looking = true;
        Cursor.visible = false;
        Cursor.lockState = CursorLockMode.Locked;
	}

    /// <summary>
    /// Disable free looking.
    /// </summary>
    public void StopLooking()
    {
        looking = false;
        Cursor.visible = true;
        Cursor.lockState = CursorLockMode.None;
	}
}