I want the text for only the GameObject I’m looking at to appear, but when I look at one of the object the floating text of all GameObject of the same type appears aswell.
This is the script
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Position3DText : MonoBehaviour {
private TextMesh TEXT;
public GameObject ItemFloatText;
void Start()
{
ItemFloatText.transform.localPosition = new Vector3 (0, 0, 0.002f);
TEXT = ItemFloatText.GetComponent<TextMesh> ();
ItemFloatText.tag = gameObject.tag;
TEXT.text = ItemFloatText.gameObject.tag;
}
void Update()
{
ItemFloatText.transform.LookAt (2 * transform.position - Camera.main.transform.position);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit Hit;
if (Physics.Raycast (ray, out Hit))
{
if ((Hit.collider.gameObject.tag == gameObject.tag) && (Vector3.Distance(Camera.main.transform.position, gameObject.transform.position) <= 3))
{
ItemFloatText.gameObject.SetActive (true);
}
else
{
ItemFloatText.gameObject.SetActive (false);
}
}
}
}
The script is inside the “Can” GameObject, the text is a child of the Can and it is (the text) assigned to the public variable “ItemFloatText”.