My Update method is shown as unused, yet I'm coding within it

I’m doing a game lesson to get basic player movement working using Unity “Lesson 2.1: Player Positioning”. I started with creating the public variables and getting the axis and the horizontal movement. The issue started with the if statement. The main idea is to use the if statement to keep the player inbounds and prevent the player from going off the side of the screen with an if-then statement. But it is not working at all; it just goes right and disappears all around the map. I’ve compared my script with theirs, and it’s the same.

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

public class PlayerController : MonoBehaviour
{
 public float horizontalInput;
 public float speed = 10.0f;

 // Update is called once per frame
 void Update()
 {
     if (transform.position.x < -10)
     {
         transform.position = new Vector3(-10, 
         transform.position.y, 
        transform.position.z);
     }
     horizontalInput = Input.GetAxis("Horizontal");
     transform.Translate(speed * Time.deltaTime * Vector3.right);
  }
 }

[![Unity Editor][2]][2]
Code

You need to change in transform.Translate in which use horizontalInput to move the player only when you make horizontalInput by using keyboard otherwise it stop

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

public class PlayerController : MonoBehaviour
{
    public float horizontalInput;
    public float speed = 10.0f;

    // Update is called once per frame
    void Update()
    {
        if (transform.position.x < -10)
        {
            transform.position = new Vector3(-10,
                transform.position.y,
                transform.position.z);
        }

        horizontalInput = Input.GetAxis("Horizontal");
        // Use horizontalInput to control the movement direction
        transform.Translate(speed * Time.deltaTime * horizontalInput * Vector3.right);
    }
}