Here are 2 scripts, can you update the 1st with the changes from the 2nd please and then provide me the complete edited script retaining all logic etc?
Script 1
using UnityEngine;
using UnityEngine.UI;

public class PlayerGrindController : MonoBehaviour
{
    [Header("Grind Settings")]
    public float grindSpeed = 0.1f;
    public bool isGrinding;

    public Transform grindPosition; // The target position on the grindable object
    public Transform localGrindDirection; // The direction of grinding (if needed)

    [Header("Grind UI")]
    public Slider grindBalanceSlider; // Assign this in the inspector

    private float grindBalance; // Represents the current balance while grinding
    private float grindBalanceTime = 4f; // Time after which the grind balance changes direction
    private bool continueGrinding; // Indicates if grinding should continue forward
    private bool intermediateMode; // Determines if the intermediate position is active
    private Transform intermediatePoint; // Optional intermediate grinding point

    private float balanceValue; // Randomly set value used to simulate balance change

    private void Update()
    {
        if (isGrinding)
        {
            GrindBalanceManager();
            GrindMovement();
        }
    }

    private void GrindBalanceManager()
    {
        // Modify the slider value over time and check if the player keeps their balance
        grindBalance += Time.deltaTime;
        if (grindBalance >= grindBalanceTime)
        {
            grindBalance = 0f;
            balanceValue = Random.Range(-30, 30); // Simulate a balance value change
        }

        // Example logic to move the grind balance slider towards the balanceValue
        grindBalanceSlider.value = Mathf.MoveTowards(grindBalanceSlider.value, balanceValue, 10f * Time.deltaTime);
    }

    private void GrindMovement()
    {
        if (continueGrinding)
        {
            // If in intermediate mode, move towards the intermediate point first
            if (intermediateMode)
            {
                if (Vector3.Distance(transform.position, intermediatePoint.position) <= 1.5f)
                {
                    intermediateMode = false;
                }
                else
                {
                    transform.position = Vector3.MoveTowards(transform.position, intermediatePoint.position, grindSpeed * Time.deltaTime);
                }
            }
            // Otherwise, move towards the main grind direction
            else
            {
                transform.position = Vector3.MoveTowards(transform.position, localGrindDirection.position, grindSpeed * Time.deltaTime);
            }
        }
    }

    public void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("GrindableSurface"))
        {
            StartGrinding(other.transform);
        }
    }

    public void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("GrindableSurface"))
        {
            EndGrinding();
        }
    }

    public void StartGrinding(Transform grindSurface)
    {
        isGrinding = true;
        continueGrinding = true;
        // Assign references or find child objects on the grindSurface to set up grinding
        grindPosition = grindSurface.GetChild(0); // Set this according to your grind object setup
        intermediatePoint = null; // Set this according to your grind object setup
        intermediateMode = false; // Set this according to your grind object setup
        localGrindDirection = grindSurface; // Example value, replace with actual alignment logic

        grindBalanceSlider.gameObject.SetActive(true); // Show the slider when grinding starts
    }

    public void EndGrinding()
    {
        isGrinding = false;
        continueGrinding = false;
        intermediateMode = false;

        grindBalanceSlider.gameObject.SetActive(false); // Hide the slider when grinding ends
    }
}
Script 2
using UnityEngine;
using UnityEngine.UI;

public class PlayerGrindController : MonoBehaviour
{
    [Header(“Grind Settings”)]
    public float grindSpeed = 0.1f;
    public bool isGrinding;

    private Transform grindPosition; // The target position on the grindable object
    private Transform localGrindDirection; // The direction of grinding (if needed)

    [Header(“Grind UI”)]
    public Slider grindBalanceSlider; // Assign this in the inspector

    private float grindBalance; // Represents the current balance while grinding
    private float grindBalanceTime = 4f; // Time after which the grind balance changes direction
    private bool continueGrinding; // Indicates if grinding should continue forward

    void Update()
    {
        if (isGrinding)
        {
            GrindBalanceManager();
            GrindMovement();
        }
    }

    private void GrindBalanceManager()
    {
        // … (balance manager code remains the same)
    }

    private void GrindMovement()
    {
        // … (movement code remains the same)
    }

    private void OnTriggerEnter(Collider other)
    {
        Grind grindScript = other.GetComponent<Grind>();
        if (grindScript != null)
        {
            StartGrinding(grindScript);
        }
    }

    private void OnTriggerExit(Collider other)
    {
        Grind grindScript = other.GetComponent<Grind>();
        if (grindScript != null)
        {
            EndGrinding();
        }
    }

    public void StartGrinding(Grind grindScript)
    {
        isGrinding = true;
        continueGrinding = true;

        // Get grind direction and position from the Grind script.
        localGrindDirection = grindScript.GetGrindDirection();
        // The grindPosition is left null here but should be set up depending on your grind system.
        // It could be a child transform of the grindable object indicating the exact grind position.

        grindBalanceSlider.gameObject.SetActive(true); // Show the slider when grinding starts
    }

    public void EndGrinding()
    {
        // … (end grinding code remains the same)
    }
}