Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class HealthBar : MonoBehaviour
- {
- private float timeSinceLastHit = 6;
- public Sprite[] bars = new Sprite[3];
- public SpriteRenderer bar;
- // Update is called once per frame
- void Update()
- {
- timeSinceLastHit -= Time.deltaTime;
- if (timeSinceLastHit <= 0)
- {
- bar.enabled = false;
- }
- transform.LookAt(Camera.main.transform);
- }
- public void Hit(int health)
- {
- timeSinceLastHit = 5;
- bar.enabled = true;
- bar.sprite = bars[health];
- }
- }
Add Comment
Please, Sign In to add comment