Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AR_Rizvi · Feb 08, 2014 at 11:19 AM · guigameobjectguitext

GameObjects name As GuiText

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 () {
 
     }
 }
 
Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image APenguin · Feb 08, 2014 at 12:18 PM 0
Share

Which object is being referenced as null? Is it every object which has the guiText above them? Could you give the exact error.

avatar image AR_Rizvi · Feb 08, 2014 at 12:37 PM 0
Share

ArgumentException: The thing you want to instantiate is null. UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message)

Exact error and i guess the object i want to instantiate is

avatar image APenguin · Feb 08, 2014 at 01:04 PM 0
Share

I think that your two GameObjects, which are activeChild and objectname might be causing you some problems. You are trying to create an instance of the object, but you haven't initialized it. So you haven't given it any value.

avatar image AR_Rizvi · Feb 10, 2014 at 04:24 AM 0
Share

I initialized it at the top both of um nd as far as active child is concern its workin fine but the problem is with objectname

avatar image AR_Rizvi · Feb 10, 2014 at 09:06 AM 0
Share

anyone else plz tell me wat i m doing wrong here or as it can be possible or not ??

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by AR_Rizvi · Feb 12, 2014 at 01:56 PM

Got It I worked With Text Mesh Nd it works perfectly

Here Is the Method OF COde I Wrote

 void OBJ_Name()
     {
         if(Show_Obj_name)
         {
             GameObject[] gameObjs = (GameObject[]) FindObjectsOfType(typeof(GameObject));
             foreach(GameObject go in gameObjs)
             {
                 if(go.GetComponent("MeshRenderer"))
                 { 
                     if(go.name.Contains(ObjectNAmeDis))
                     {
                         Preobjectname =GameObject.Instantiate(objectname)as GameObject ;
 //                GUIText name = objectname.GetComponent<GUIText>();
                         if(Preobjectname.GetComponent<TextMesh>())
                         {
 //                            Preobjectname.AddComponent<TextMesh>();
                             TextMesh name = Preobjectname.GetComponent<TextMesh>();
                             name.text = go.name; // Change Me
                             name.font = fon ;
                             name.fontSize = 5;
                             name.anchor = TextAnchor.UpperCenter ; 
                             name.alignment = TextAlignment.Center ;
                             name.offsetZ = 0;
                             name.color = Color.red;
                             name.characterSize = 1;
                             name.richText = false;
                             
                             Preobjectname.transform.position = go.transform.position; 
                             Preobjectname.transform.eulerAngles = go.transform.eulerAngles ;
 
                             Preobjectname.transform.rotation = Quaternion.Euler(90f,25f,80f);
 
                             objs.Add(Preobjectname);
                         }
                         else
                         {
 
                         }
                     }
                 }
             }
         }
         else
         {
             foreach(GameObject _Object in objs)
             {
                 Destroy(_Object);
             }
 
         }
             
     }

Can See Every Game Object's Name With it Thanks AR

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Jasper-Flick · Feb 08, 2014 at 03:45 PM

The error tells you're trying to instantiate something that is null. You're instantiating something in one place, and it is Resources.Load("HoverText"). So the loading failed. Check whether the HoverText file is in your Assets/Resources folder and whether you spelled it correctly.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AR_Rizvi · Feb 10, 2014 at 04:28 AM 0
Share

yup its in the folder and it spelld right wat is going wrong then

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What's wrong with my function? It keeps telling me 'loseText' is not a member of 'UnityEngine.GUIText'. Please help, please and thank you! 0 Answers

Problems using NGUI for in-game options sliders 0 Answers

How to make text appear when moving next to an object? 3 Answers

Unity3D Game Time 1 Answer

create a GuiSkin 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges