Hi Guys
I am Trying to Display gameObjects name on screen in GameView By Gui Text But Experincing a problem
Unity is sayng that the object is null which i am instanciating it Can anyone Suggets what i am doing wrong here
basicaly i want that each of my game object has its name above them as guitext or anything else and all guitext be destroyed to when the need is over like toggel
plz help
Thanks
here is my code
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
public class JUMP_Caracter : MonoBehaviour {
string stringToEdit = "Building no";
public GameObject player ;
GameObject activeChild;
bool Show_boumdingboxes = false ;
bool Disable_scale_Script = false ;
bool Show_Obj_name = false ;
GameObject objectname ;
void OnGUI() {
GUILayout.Window(0,new Rect(10, 80, 600, 120), DoMyWindow, "Position");
}
void DoMyWindow(int windowID) {
stringToEdit = GUILayout.TextField(stringToEdit, 25);
if (GUILayout.Button("Go to Building's Position"))
{
Change_Position();
}
// Show_boumdingboxes = GUILayout.Toggle(Show_boumdingboxes, "Show Colliders") ;
Disable_scale_Script = GUILayout.Toggle(Disable_scale_Script, "Enable Gui Point to Point Scale") ;
if (GUILayout.Button("Do"))
{
Set_Scale();
}
Show_Obj_name = GUILayout.Toggle(Show_Obj_name, "Enable Game Objects Name ");
if (GUILayout.Button("Do"))
{
OBJ_Name();
}
}
// Use this for initialization
void Start () {
}
void Change_Position()
{
GameObject[] gameObjs = (GameObject[]) FindObjectsOfType(typeof(GameObject));
foreach(GameObject go in gameObjs)
{
if(go.name.Contains("_BLD_"))
{
string building_name = go.name;
if(building_name.Contains(stringToEdit))
{
GameObject obj = GameObject.Find(building_name);
SetLayer();
activeChild.transform.position = obj.transform.position;
// activeChild.transform.position = new Vector3 (obj.transform.position.x+8,obj.transform.position.y,obj.transform.position.z);
// activeChild.transform.eulerAngles.y = obj.gameObject.transform.eulerAngles.y;
string[]name = building_name.Split(char.Parse("_"));
}
}
}
}
void SetLayer ()
{
foreach(Transform Child in player.transform)
{
if(Child.active)
activeChild = Child.transform.gameObject;
}
}
void Set_Scale()
{
if(Disable_scale_Script)
{
gameObject.AddComponent("Draw_LINE_ON_GUI_P2P_dist");
}
else
{
Destroy(GetComponent("Draw_LINE_ON_GUI_P2P_dist"));
}
}
void OBJ_Name()
{
if(Show_Obj_name)
{
GameObject[] gameObjs = (GameObject[]) FindObjectsOfType(typeof(GameObject));
foreach(GameObject go in gameObjs)
{
objectname = GameObject.Instantiate(Resources.Load("HoverText")) as GameObject;
GUIText name = objectname.GetComponent<GUIText>();
name.text = go.name; // Change Me
objectname.transform.position = go.transform.position + new Vector3(0f, 5f, 0f); // Change the 0.05f value to some other value for desired height
}
}
else
{
// objectname.Remove();
}
}
// Update is called once per frame
void Update () {
}
}