localScale Changes the scale form the center and not the left
Hey everyone! So, I’m currently making a game and I’m at the part of adding a health bar to my character. Everything works! When an enemy hit me, I lose health! the only problem is that when ever I lose health the bar scales down to the middle and not from one end to the other like a normal health bar!
Here's the code that handle the scale of my health bar
/// <summary>
/// Mets à jour les divers éléments qui représente la vie du joueur.
/// </summary>
private void MettreAJourBarreVie()
{
// Normalise les points de vie.
m_pointsVieNormalise = 1f * m_pointsVie / m_maxPointsVie;
// Ajuste la barre selon les points de vie normalisés.
m_barreVie.localScale = new Vector3(m_pointsVieNormalise, 1f, 1f);
// Remplace le texte avec la nouvelle valeur.
m_texteVie.text = $"{m_pointsVie} Go libres sur {m_maxPointsVie} Go";
}
Answer by tormentoarmagedoom · May 23, 2019 at 07:45 AM
hello.
IS the bar a canvas image? or is a object in scene?
If its a image in canvas, you only need to change its pivot in its RectTrasnform component.
If its a object, you should make the bar child of an emptyobject, and this emptyobject will act as pivot, so must be places at the corner of the bar.
Bye!
Your answer
Follow this Question
Related Questions
Canvas scaler issues (not scaling properly) 1 Answer
How to reduce the scale of the x and z axis ,How to reduce the x and z scale in a time lapse 0 Answers
I need help with my Healthbar. 0 Answers
Little problem: fit to any phone 3 Answers
Many objects with decimal place in the millionths, can this cause any performance issues? 0 Answers