-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHealthBarScript.cs
More file actions
35 lines (30 loc) · 913 Bytes
/
Copy pathHealthBarScript.cs
File metadata and controls
35 lines (30 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class HealthBarScript : MonoBehaviour
{
private EnemyScript es;
private float health;
private Slider slider;
private CanvasGroup sliderCG;
// Start is called before the first frame update
void Start()
{
es = transform.root.GetComponent<EnemyScript>();
slider = GetComponent<Slider>();
sliderCG = slider.GetComponent<CanvasGroup>();
}
// Update is called once per frame
void Update()
{
health = es.health;
slider.value = health * .01f;
transform.LookAt(es.Target.position);
if (Vector3.Distance(transform.position, es.Target.position) < 3 && !es.dead)
sliderCG.DOFade(1, 0.5f);
else
sliderCG.DOFade(0,.5f);
}
}