Mouse Rotation And Movement Script with Character Controller

I’ve been working on a game for nearly a week and, being a near-complete noob with lots of programming experience in anything but c#, I’m stuck while making a movement script.

This is my current code:

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

public class Movement : MonoBehaviour
{

 public CharacterController controller;
 public Vector3 MovementSpeed;
 public float MouseSpeed;

 // Start is called before the first frame update
 void Start()
 {

 }

 // Update is called once per frame
 void Update()
 {
     #region BasicMovement

     if (Input.GetKeyDown(KeyCode.LeftShift))
     {
         if (Input.GetKeyDown(KeyCode.W)) MovementSpeed.z += 4;
         if (Input.GetKeyDown(KeyCode.A)) MovementSpeed.x -= 4;
         if (Input.GetKeyDown(KeyCode.S)) MovementSpeed.z -= 4;
         if (Input.GetKeyDown(KeyCode.D)) MovementSpeed.x += 4;
         if (Input.GetKeyUp(KeyCode.W)) MovementSpeed.z -= 4;
         if (Input.GetKeyUp(KeyCode.A)) MovementSpeed.x += 4;
         if (Input.GetKeyUp(KeyCode.S)) MovementSpeed.z += 4;
         if (Input.GetKeyUp(KeyCode.D)) MovementSpeed.x -= 4;
     }
     else
     {
         if (Input.GetKeyDown(KeyCode.W)) MovementSpeed.z += 2;
         if (Input.GetKeyDown(KeyCode.A)) MovementSpeed.x -= 2;
         if (Input.GetKeyDown(KeyCode.S)) MovementSpeed.z -= 2;
         if (Input.GetKeyDown(KeyCode.D)) MovementSpeed.x += 2;
         if (Input.GetKeyUp(KeyCode.W)) MovementSpeed.z -= 2;
         if (Input.GetKeyUp(KeyCode.A)) MovementSpeed.x += 2;
         if (Input.GetKeyUp(KeyCode.S)) MovementSpeed.z += 2;
         if (Input.GetKeyUp(KeyCode.D)) MovementSpeed.x -= 2;
     }

     controller.SimpleMove(MovementSpeed);

     #endregion

     #region Rotation

     if (Input.GetAxis("Mouse X") > 0) transform.Rotate((Vector3.up) * MouseSpeed);
     if (Input.GetAxis("Mouse X") < 0) transform.Rotate((Vector3.up) * -MouseSpeed);
     #endregion
 }

}
As shown in the code, I’m using a character controller instead of a rigidbody and missing an up/down look script.

The code currently uses the old input system, and I’m hoping to update it to the new system once this movement script is complete, as all I have to do is change the input methods.

P.S. I posted this in help room as well and since I posted it there I updated my move script to the new input system but I’m still stuck and could really do with some help with the actual movement.

I can see why you are stuck, there are some odd things like GetKeyDown and a movespeed that increases… (?)
you kind of combined movement direction and speed.
it should be sepperate.

so rewrote your code. with comments.

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

public class Movements : MonoBehaviour
{

    public CharacterController controller;
    public Vector3 MovementDirection;
    public int MoveSpeed = 2;
    public float MouseSpeed = 2f;

    // Update is called once per frame
    void Update()
    {
        #region BasicMovement

        //holding leftshift, move speed will be 4.
        if (Input.GetKey(KeyCode.LeftShift))
        {
            MoveSpeed = 4;
            //if (Input.GetKeyDown(KeyCode.W)) MovementSpeed.z += 4;
            //if (Input.GetKeyDown(KeyCode.A)) MovementSpeed.x -= 4;
            //if (Input.GetKeyDown(KeyCode.S)) MovementSpeed.z -= 4;
            //if (Input.GetKeyDown(KeyCode.D)) MovementSpeed.x += 4;
            //if (Input.GetKeyUp(KeyCode.W)) MovementSpeed.z -= 4;
            //if (Input.GetKeyUp(KeyCode.A)) MovementSpeed.x += 4;
            //if (Input.GetKeyUp(KeyCode.S)) MovementSpeed.z += 4;
            //if (Input.GetKeyUp(KeyCode.D)) MovementSpeed.x -= 4;
        }
        else
        {
            //but normaly , the move speed is  2
            MoveSpeed = 2;
            //    if (Input.GetKeyDown(KeyCode.W)) MovementSpeed.z += 2;
            //    if (Input.GetKeyDown(KeyCode.A)) MovementSpeed.x -= 2;
            //    if (Input.GetKeyDown(KeyCode.S)) MovementSpeed.z -= 2;
            //    if (Input.GetKeyDown(KeyCode.D)) MovementSpeed.x += 2;
            //    if (Input.GetKeyUp(KeyCode.W)) MovementSpeed.z -= 2;
            //    if (Input.GetKeyUp(KeyCode.A)) MovementSpeed.x += 2;
            //    if (Input.GetKeyUp(KeyCode.S)) MovementSpeed.z += 2;
            //    if (Input.GetKeyUp(KeyCode.D)) MovementSpeed.x -= 2;
        }

        //Axis Horizontal/Vertical are mapped to the arrow keys and wasd.
        // this returns 0 when not pressed.
        // -1 when arrow left, and +1 when arrow right.
        MovementDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

        // and you can multiply a Vector3 by a number.
        controller.SimpleMove(MovementDirection * MoveSpeed);

        #endregion

        #region Rotation

        //this means that this can be shortened too.
        //instead of this:
        //if (Input.GetAxis("Mouse X") > 0) transform.Rotate((Vector3.up) * MouseSpeed);
        //if (Input.GetAxis("Mouse X") < 0) transform.Rotate((Vector3.up) * -MouseSpeed);

        //use 
        transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * MouseSpeed);
        #endregion
    }
}

Thanks for the help and I think I get how the code works @trannel. How would I implement up/down rotation as well, since the current code only goes left/right.