The temp S button on the bottom right enables and disables the object names, the code is here.
void Update () {
if (showName == true) DisplayNameOn (true);
}
void DisplayNameOn (bool showName) { // Gets called on Broadcast or if HoverText is On.
if (showName == false) {
HoverTextfolder = GameObject.Find("HoverText");
Info.showName = true;
hoverText = GameObject.Instantiate(Resources.Load("Hover Text")) as GameObject;
GUIText name = hoverText.GetComponent<GUIText>();
name.text = Name;
hoverText.transform.parent = HoverTextfolder.transform;
}
if (hoverText) hoverText.transform.position = Camera.main.WorldToViewportPoint(transform.position) + new Vector3(-0.006f, 0.03f, 0f); // Change the 0.05f value to some other value for desired height
}
}
The Satellite named Callisto and Europa is behind me and shows up on my main Camera. Same as vice versa.
I haven’t tested this, but it should work perfectly.
Use the following code:
OnCameraMove () { // Wherever you handle your camera movement
// Movement calculations
GameObject[] satelites = GameObject.FindGameObjectsWithTag("WhateverYouCallYourSatelites");
// every time you move your camera you can step through all the satellites to see if you should turn their names on or off
foreach (GameObject go in satelites) {
if (IsBehind(Camera.maincamera, go)) {
go.GetComponent<NameOfScriptOnObjectThatHandlesTheNameDisplay>().TurnNameOff(); // Where the TurnNameOff() method is whatever method you use to turn the name on or off
}
else {
go.GetComponent<NameOfScriptOnObjectThatHandlesTheNameDisplay>().TurnNameOn();
}
}
}
//Checks if targetOther is behind targetThis
bool IsBehind(gameObject targetThis, targetOther) {
Vector3 toTarget = (targetOther.position - targetThis.position).normalized;
return (Vector3.Dot(toTarget, transform.forward) > 0);
}
thx for your reply, take a look at my answer see if you find it simplified.
– d112570