Touch Controls not allowing me to move the character not really sure why

I am trying to get on screen touch control to work for, all the button but the left and right arrows for the movement are working and I can’t really understand where I went wrong with the logic, pretty new to Unity and this had been driving me mad z

//Play Controller script

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

public class PlayerMovement : MonoBehaviour
{

    public ParticleSystem Dust;


    //Animation States
    const string IDLE_ANIMATION = "Idle_an";
    const string JUMP_ANIMATION = "Jump_an";
    const string RUN_ANIMATION = "Run_an";
    const string PICKAXE_ATTACK_ANIMATION = "Pickaxe_an";
    private float horizontal;
    public float speed = 5f;
    private float jumpingPower = 13f;
    private bool isFacingRight = true;
    private bool isJumpPressed;
    private bool isAttacking;
    private bool isAttackingPressed;

    public Transform attackHitBox;
    public float attackRange = 0.5f;
    public LayerMask enemyLayers;

    private float coyoteTime = 0.2f;
     private float coyoteTimeCounter;

     private float jumpBufferTime = 0.2f;
     private float jumpBufferCounter;

     public int damageToGive;
  
     [SerializeField] private Rigidbody2D rb;
     [SerializeField] private Transform groundCheck;
     [SerializeField] private LayerMask groundLayer;
     [SerializeField] private float attackDelay = 1f;
     Animator animator;
     private string currentState;
     void Start()
     {
        animator = GetComponent<Animator>();
     }


    // So I can make the Rigidbody acccessible to othe scripts
    //While keeping the main one private with the player controller
     public Rigidbody2D PlayerRigidbody
    {
    get { return rb; }
    set { rb = value; }
    }

    
    


 
    void Update()
    {
        Move(Input.GetAxisRaw("Horizontal"));
        /*Returns a raw value of the axis input. Which means it will return either -1,0 or 1 Depending on the direction of the input
        -1 = (left,down), 1 = (right,up) 0 = there is no input*/
        //horizontal = Input.GetAxisRaw("Horizontal");
        //This allows a brief window which allows the player to jump even though they are not touching the ground
        //Just like coyote not falling straight away when he runs off the edge in roadrunner.

        if(isGrounded())
        {
            coyoteTimeCounter = coyoteTime;

        }else
        {
            coyoteTimeCounter -= Time.deltaTime;

        }
        //Allows the player buffer a jump while they are in the air, strictly a game feel thing.
       
        if(Input.GetButtonDown("Jump"))
        {
            jumpBufferCounter = jumpBufferTime;

        }else
        {
            jumpBufferCounter -= Time.deltaTime;

        }



        if(jumpBufferCounter > 0f && coyoteTimeCounter > 0f)
        {
            isJumpPressed = true;
            rb.velocity = new Vector2(rb.velocity.x, jumpingPower);

            jumpBufferCounter = 0f;
        }

        if(Input.GetButtonUp("Jump") && rb.velocity.y > 0f)
        {
            rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
            coyoteTimeCounter = 0f;

        }

       
         
        Flip();

        //if(Input.GetMouseButtonDown(0))
        //{
        // PickAxe();
       // }
       
    }

    public void Jump()
    {
        if(isGrounded())
        {
             isJumpPressed = true;
             rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
        }

    }

     public void Move(float moveInput)
    {
         horizontal = moveInput;
    }
    /*Fixed update is a method used in Unity used for physics calculations.
    Its a special function that runs a fixed number of times per second.
    Itis designed to update the position, velocity and other physical properties*/
    private void FixedUpdate()
    {
        /*Overall, this code is setting the velocity of a Rigidbody2D component based on the horizontal input (stored in the "horizontal" variable)
        and a speed value (stored in the "speed" variable).
        This can be used to move the object left and right in response to user input*/
        rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);

        //This is for the change in animation, I don't want this to overriding, things like the jump animation so we check if we are grounded first
        if(isGrounded() && !isAttacking){
            if(horizontal != 0f)
            {
                ChangeAnimationState(RUN_ANIMATION);
                CreateDust();

            }
            else if(horizontal == 0)
            {  
            ChangeAnimationState(IDLE_ANIMATION);
            }
   
        }

        if(isJumpPressed = true && !isGrounded() && !isAttacking){
           
            ChangeAnimationState(JUMP_ANIMATION);
        }

        if(isAttackingPressed)
        {
            isAttackingPressed = false;

            if(!isAttacking)
            {
                isAttacking = true;
                Attack();

            }
            Invoke("AttackComplete", attackDelay);

        }
       

       

    }


  
    public void PickAxe()
    {
        isAttackingPressed = true;
    }





    void Attack()
    {
        ChangeAnimationState(PICKAXE_ATTACK_ANIMATION);
        Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackHitBox.position, attackRange, enemyLayers);

        foreach(Collider2D enemy in hitEnemies)
        {
            Debug.Log("we hit" + enemy.name);
            enemy.GetComponent<EnemyHealthManager>().giveDamage(damageToGive);
           
        }


    }

    void OnDrawGizmosSelected()
    {
        if (attackHitBox == null)
            return;

        Gizmos.DrawWireSphere(attackHitBox.position, attackRange);
    }

    void AttackComplete()
    {
        isAttacking = false;

        if (isGrounded())
    {
        if (horizontal != 0f)
        {
            ChangeAnimationState(RUN_ANIMATION);
            CreateDust();
        }
        else
        {
            ChangeAnimationState(IDLE_ANIMATION);
        }
    }
    else
    {
        ChangeAnimationState(JUMP_ANIMATION);
    }
    }

    private bool isGrounded()
    {  
        /*Checks if the gameObject is currently on the ground. Creates a small gameObject
        slightly below the player*/
        //The "0.2f" value is the radius of the circle.
        //The "groundLayer" parameter is a layer mask that's used to filter out other objects that we don't want to check for collisions with.
        //The "groundCheck" transform is an empty game object that's placed at the bottom of the game object's sprite.
   
        return Physics2D.OverlapCircle(groundCheck.position, 0.1f, groundLayer);

    }

    private void Flip()
    {  
        //If statement used to filp the player, checks what direction they are moving in
        //flips the player on the x Axis depending on the direction
        if(isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
        {
            isFacingRight = !isFacingRight;
            Vector3 localScale = transform.localScale;
            localScale.x *= -1f;
            transform.localScale = localScale;
        }

    }

    void ChangeAnimationState(string newState)
    {
        //stop the same animation from interrupting itself
        if (currentState == newState) return;
       
        //play the animation
        animator.Play(newState);

        currentState = newState;

    }

    void CreateDust()
    {
        Dust.Play();

    }
}

//Touch Control scripts

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

public class TouchControls : MonoBehaviour
{

    private PlayerMovement thePlayer;
    // Start is called before the first frame update
    void Start()
    {
        thePlayer = FindObjectOfType<PlayerMovement>();
       
    }

    public void LeftArrow()
    {
        thePlayer.Move(-1);
    }

     public void RightArrow()
    {
        thePlayer.Move(1);

    }

    public void UnpressedArrow()
    {
        thePlayer.Move(0);

    }

    public void PickAxe_Attack()
    {
        thePlayer.PickAxe();

    }

    public void JumpButton()
    {
        thePlayer.Jump();

    }

Fix it I put it in to the start() instead and it worked

Fix your errors first. Until all errors are fixed, all results are irrelevant.

How to fix a NullReferenceException error

https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

Three steps to success:

  • Identify what is null ← any other action taken before this step is WASTED TIME
  • Identify why it is null
  • Fix that

After that, which should take only minutes, if you still have a problem them it is…

Time to start debugging! Here is how you can begin your exciting new debugging adventures:

You must find a way to get the information you need in order to reason about what the problem is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

What is often happening in these cases is one of the following:

  • the code you think is executing is not actually executing at all
  • the code is executing far EARLIER or LATER than you think
  • the code is executing far LESS OFTEN than you think
  • the code is executing far MORE OFTEN than you think
  • the code is executing on another GameObject than you think it is
  • you’re getting an error or warning and you haven’t noticed it in the console window

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run? what order does it run in?
  • what are the names of the GameObjects or Components involved?
  • what are the values of the variables involved? Are they initialized? Are the values reasonable?
  • are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

Knowing this information will help you reason about the behavior you are seeing.

You can also supply a second argument to Debug.Log() and when you click the message, it will highlight the object in scene, such as Debug.Log("Problem!",this);

If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

You could also just display various important quantities in UI Text elements to watch them change as you play the game.

Visit Google for how to see console output from builds. If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer or iOS: How To - Capturing Device Logs on iOS or this answer for Android: How To - Capturing Device Logs on Android

If you are working in VR, it might be useful to make your on onscreen log output, or integrate one from the asset store, so you can see what is happening as you operate your software.

Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

“When in doubt, print it out!™” - Kurt Dekker (and many others)

Note: the print() function is an alias for Debug.Log() provided by the MonoBehaviour class.