Question by
spookenzi · Jan 02, 2018 at 10:05 PM ·
characterscripting beginneropacity
Displaying Players Health via Opacity of character
Hi, I am new to Unity and building my first 2D game.
The Idea of this game is there is boy who needs to collect lights in order to survive, As time flows he gets less opacity until fades away completely. (The more health he has the more light is in him and vice versa)
Can anyone help me how to adjust opacity based on his current health level?
Here is code I wrote for the health mechanism
public float life = 100;
public float timeKill = 0.1f;
void Update()
{
life -= timeKill;
Debug.Log(life);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Collectable")
{
Destroy(other.gameObject);
life += 20;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612145706im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Opacity object 1 Answer
My Character dosen´t move 0 Answers
Interesting Script Problem 1 Answer
How do I make my player model rotate based on the direction he is walking. 0 Answers