- Home /
Inverting the cutoff property (UI bar)
Hi, I'm making a sprite based hud in my game, and I'm using the cutoff shader to get the bars working, the problem is that the cutoff property is "inverted" in some way, like when it's at 0, it shows everything, and when it's at 1, it shows nothing, and I want the exact opposite (e.g. if I have 100 hp I want it to draw the whole bar, if I have 0 I want it to draw nothing).
Here is my current code for the bar:
float energyQuanitity = EnergyBar.GetFloat("_Cutoff");
energyQuanitity = Mathf.Lerp(energyQuanitity, EnergyScript.energy/100f, lerpSpeed * Time.deltaTime);
EnergyBar.SetFloat("_Cutoff", energyQuanitity);
and here's the full script:
using UnityEngine;
using System.Collections;
public class HudScript : MonoBehaviour {
public float lerpSpeed = 10f;
public Color FirstColor = Color.black;
public Color SecondColor;
Color currentColor;
public GUITexture vignette;
public Material EnergyBar;
public Material TemperatureBar;
void Start () {
currentColor.a = 1f;
}
void Update () {
currentColor = Color.Lerp(FirstColor, SecondColor, GameManager.temperatureChange/30f);
vignette.color = currentColor;
TemperatureBar.SetFloat("_Cutoff", GameManager.temperatureChange/30f);
float energyQuanitity = EnergyBar.GetFloat("_Cutoff");
energyQuanitity = Mathf.Lerp(energyQuanitity, EnergyScript.energy/100f, lerpSpeed * Time.deltaTime);
EnergyBar.SetFloat("_Cutoff", energyQuanitity);
}
}
Thanks in advance.
I'm sorry, but could you edit that into the full script? I'll edit the question
Its the same problem with the UI to Image positioning. Get the max value. in this case its 1.0f and just subtract the value from your calculations.
float energyQuanitity = EnergyBar.GetFloat("_Cutoff");
energyQuanitity = $$anonymous$$athf.Lerp(energyQuanitity, EnergyScript.energy/100f, lerpSpeed * Time.deltaTime);
EnergyBar.SetFloat("_Cutoff", **1.0f - energyQuanitity**);
hmmm now it's just acting weird, it doesn't start at max (it kinda defines a new maximum) and it's acting choppy
edit: apparently it's the lerp that is bugging it
Your answer
![](https://koobas.hobune.stream/wayback/20220613154900im_/https://answers.unity.com/themes/thub/images/avi.jpg)