-
Notifications
You must be signed in to change notification settings - Fork 0
/
FloatingDamage.cs
46 lines (42 loc) · 1.67 KB
/
FloatingDamage.cs
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
36
37
38
39
40
41
42
43
44
45
46
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class FloatingDamage : MonoBehaviour
{
public GameObject floatingDamagePrefab;
private List<GameObject> floatingDamageObjects = new List<GameObject>();
private GameObject currentObject;
public Transform startMarker;
public Transform endMarker;
public void SpawnDamageNumber(int damageAmt)
{
if(floatingDamageObjects.Count < 10)
{
currentObject = (Instantiate(floatingDamagePrefab as GameObject, transform));
floatingDamageObjects.Add(currentObject);
}
else
{
for(int i = 0; i < floatingDamageObjects.Count; i++)
{
if (!floatingDamageObjects[i].activeSelf)
{
currentObject = floatingDamageObjects[i];
currentObject.SetActive(true);
currentObject.transform.position = transform.position;
currentObject.GetComponent<MoveDamageValue>().ResetPosition();
break;
}
}
}
currentObject.GetComponent<MoveDamageValue>().SetMarkers(startMarker, endMarker);
currentObject.GetComponent<TextMeshProUGUI>().text = damageAmt.ToString();
if(damageAmt == 1)
currentObject.GetComponent<TextMeshProUGUI>().color = Color.red;
else if (damageAmt == 2)
currentObject.GetComponent<TextMeshProUGUI>().color = Color.blue;
else if (damageAmt > 2)
currentObject.GetComponent<TextMeshProUGUI>().color = Color.yellow;
}
}