Hi!
I have 3 races in my game which accord to 3 palyer tags (PlayerRace1, PlayerRace2, PlayerRace3). Every race has certain color for character’s name above head but i need character one race to see green color above head but if character’s are in different teams they see Race color.
public class ObjectLabel : MonoBehaviour
{
private Transform _go;
void Awake()
{
_go = this.transform.parent;
}
void Start()
{
if (_go.tag == "PlayerRace1") //0 255 96 255 ---> for friends!
{
GetComponent<GUIText>().color = new Color32(192, 184, 96, 255);
}
else if (_go.tag == "PlayerRace2")
{
GetComponent<GUIText>().color = new Color32(136, 91, 229, 255);
}
else if (_go.tag == "PlayerRace3")
{
GetComponent<GUIText>().color = new Color32(60, 165, 191, 255);
}
}
void Update()
{
Vector3 cameraRelative = Camera.main.transform.InverseTransformPoint(_go.FindChild("AboveGUIPosition").position);
if (_go.gameObject.tag.Contains("Player"))
{
if (cameraRelative.z > 0)
{
Positioning();
}
if (_go.tag == "PlayerRaceEnemy")
{
GetComponent<GUIText>().color = new Color32(219, 18, 85, 235);
}
}
else if (_go.gameObject.tag == "Creature")
{
if (cameraRelative.z > 0)
{
Positioning();
}
}
}
void Positioning()
{
Vector3 pos = Camera.main.WorldToViewportPoint(_go.FindChild("AboveGUIPosition").position);
transform.position = pos;
}
}
So how to do this if every character has his own GUIText? Should i use Raycast or not?