-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerIndicator.cs
More file actions
46 lines (40 loc) · 1.24 KB
/
PlayerIndicator.cs
File metadata and controls
46 lines (40 loc) · 1.24 KB
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
// selection indicator
using UnityEngine;
namespace uMMORPG
{
public class PlayerIndicator : MonoBehaviour
{
[Header("Indicator")]
public GameObject indicatorPrefab;
[HideInInspector] public GameObject indicator;
public void SetViaParent(Transform parent)
{
if (!indicator) indicator = Instantiate(indicatorPrefab);
indicator.transform.SetParent(parent, true);
indicator.transform.position = parent.position;
}
public void SetViaPosition(Vector3 position)
{
if (!indicator) indicator = Instantiate(indicatorPrefab);
indicator.transform.parent = null;
indicator.transform.position = position;
}
// clear indicator if there is one, and if it's not on a target
public void ClearIfNoParent()
{
if (indicator != null && indicator.transform.parent == null)
Destroy(indicator);
}
// clear in any case
public void Clear()
{
if (indicator != null)
Destroy(indicator);
}
void OnDestroy()
{
if (indicator != null)
Destroy(indicator);
}
}
}