Mathf.Clamp not working

Could someone explain me why is mathf.clamp not claming value of normalizedValue ?
I tried using clamp in several ways before asking, but it jsut seems to be not affecting anything.

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

public class HealthBar : MonoBehaviour
{
    public float displayedMaxValue=100;
    public float displayedCurrentValue=100;
 
    private float normalizedValue;
    public Transform bar;
    // Start is called before the first frame update
    void Start()
    {

        displayedCurrentValue = -50;
     
    }
    private void Update()
    {
       

        Mathf.Clamp(normalizedValue = displayedCurrentValue / displayedMaxValue, 0, 1);
     
        bar.localScale = new Vector3(normalizedValue,1f,1f);
    }

}

Because you are ignoring its result.

Also, it’s bad form to do an assignment within the argument to a function. Just don’t do it.

Perhaps you meant this?

normalizedValue = Mathf.Clamp(displayedCurrentValue / displayedMaxValue, 0, 1);
2 Likes
campos.x = Mathf.Clamp(campos.x, 0, xmax);
campos.z = Mathf.Clamp(campos.z, 0, zmax);