Skip to content
Snippets Groups Projects
Verified Commit e77ca7fd authored by Adrian Paschkowski's avatar Adrian Paschkowski :thinking:
Browse files

Fix health bar scale if parent scale is different

parent 44c4b539
No related branches found
No related tags found
No related merge requests found
......@@ -7,11 +7,13 @@ public class HealthBarController : MonoBehaviour
[SerializeField] Color barColor = new Color(245, 17, 17);
Transform bar;
Vector3 initialScale;
void Awake()
{
bar = transform.Find("Bar");
bar.Find("Health").GetComponent<SpriteRenderer>().color = barColor;
initialScale = transform.localScale;
}
private void Update()
......@@ -20,7 +22,7 @@ public class HealthBarController : MonoBehaviour
// If transform.parent.localScale.x is -1, the health bar scale will be set to -1
// as well, effectively cancelling the flip.
var scale = transform.localScale;
scale.x = transform.parent.localScale.x;
scale.x = transform.parent.localScale.x < 0 ? -initialScale.x : initialScale.x;
transform.localScale = scale;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment