I have a timer that is represented as a bar. The timer will be initialized by an arbitrary value (for example, 5 ), and this will represent the entire bar. But as time passes, I want to scale it smaller. This is what I currently have so far.
float fullTime = 5.0f;
float currentTime = 5.0f;
void Update()
{
currentTime -= Time.DeltaTime;
float ratio = currentTime / fullTime;
Vector3 currentScale = transform.localScale;
transform.localScale = new Vector3(Mathf.Clamp(ratio, 0f, 1f), currentScale.y, currentScale.z);
}
But this scales the bar toward the center of the bar. I want it to scale from right to left (So the bar will shrink by moving down to the left side of the bar).
Whats complicating is that this is a child gameobject, like calculating the leftside’s position by
Vector3 oldLeftPos = transform.position;
oldLeftPos.x -= transform.GetComponent<SpriteRenderer>().bounds.extends.x;
and after I did the scaling I did the following
Vector3 newLeftPos = transform.position;
newLeftPos.x -= transform.GetComponent<SpriteRenderer>().bounds.extends.x;
newLeftPos.x = newLeftPos.x - (newLeftPos.x - oldLeftPos.x);
transform.InverseTransformPoint(newLeftPos);
But it’s still converging toward the center. Can any one help me or point out what I’m doing wrong?