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 SuperSparkplug · Nov 05, 2013 at 10:26 AM · instantiateprefabtext

Make Mesh & Text disappear

Hi, so I have my game project where the player is asked questions, responds by going through doors, and it instantiates a new room prefab on the other side of the door for the player to go through, however I'm having an issue where the old room and text that was created for it still linger and cause some confusion for the player and obscure the part of the new room and new question text.

alt text

I'm not exactly sure what to do in this case. I'm not sure how to tell the mesh render for the previous room to turn off, delete, or become transparent to some degree when the player passes through the door or triggers a condition. I need some solution to at the very least get rid of the text from the previous room. The text, which is generated by reading a text file, is being generated through a script that goes like this.

             if(gameObj.name == "Body")
             {
     
                 objText.Add( new GameObject("TextObject") );
                 
                 TextMesh textMesh = objText.Last().AddComponent<TextMesh>();
                 Font ArialFont = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
                 textMesh.font = ArialFont;
                 //textMesh.text = "Hello World!";
                 textMesh.text = Util.WordWrap ( "A" + (doorAnswer+1) + ") " + content.answers[doorAnswer], 10 );
                 textMesh.renderer.material = ArialFont.material;
                 
                 
                 //Answers
                 GameObject door = gameObj;
                 textMesh.transform.rotation = door.transform.rotation;
                 textMesh.transform.position = new Vector3(door.transform.position.x - 6, door.transform.position.y + 10, door.transform.position.z); //- cube.renderer.bounds.size.x / 2
                 textMesh.transform.Rotate(Vector3.up, -90, Space.Self);    
                 
                 //0th is left door, 1th center, 2nd right
                 if (doOnceOnly == 1){
                     //put question above center door
                     //Question
                     objText.Add( new GameObject("TextObject") );
                     
                     TextMesh textMesh2 = objText.Last().AddComponent<TextMesh>();
                     textMesh2.font = ArialFont;
                     textMesh2.text = Util.WordWrap ( "Q" + content.qNum + ") " + content.question, 20 );
                     textMesh2.renderer.material = ArialFont.material;
 
                     textMesh2.transform.rotation = door.transform.rotation;    
                      textMesh2.transform.position = new Vector3(door.transform.position.x - 8, door.transform.position.y + 20, door.transform.position.z); //- cube.renderer.bounds.size.x / 2
                      textMesh2.transform.Rotate(Vector3.up, -90, Space.Self);
                     
                     doOnceOnly++;
                 }
                 else {
                     doOnceOnly++;
                 }
                 
                 
 
                 doorAnswer++;

Also, after the first room, for some reason, the Question text is always off to the side instead of centred and I can't seem to figure out why. Any ideas on what exactly I should do in this situation?

screen shot 2013-11-05 at 4.04.17 am.png (200.6 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Berenger · Nov 05, 2013 at 11:19 AM

Once you get to a new room, you'll have to hide the stuff from the previous one by using SetActive, renderer.enabled or a transparent material.

For that, you'll need the reference of the objects from the previous room. Is suggest a to parent them to a single gameObject.

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 MattTheProgrammer · Nov 05, 2013 at 11:41 AM

From what I see you want to destroy a gameObject that the script is not attached to.

Make the text dissapear:

 GameObject.Find("Name").GetComponent(MeshRenderer).enabled = false;

As for the question always off to the side, Maybe you could keep messing around with the spawn co-ordinates until you find something thats good.

Comment
Add comment · Show 2 · 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 MattTheProgrammer · Nov 05, 2013 at 11:17 AM 0
Share

Also, you should name you new text something different to the other ones

avatar image SuperSparkplug · Nov 06, 2013 at 04:53 AM 0
Share

Any clue on how to do that? Also, I put in your fix and Unity keeps giving me errors. First I put it alone in my code and that didn't work, than I assigned it to GameObject variables and that doesn't work either. Exactly how should that be implemented?

EDIT: I was able to use the Destroy command to delete the text. HOWEVER, it won't stop deleting the text. As soon as I open a door to trigger the text's destruction, all text is destroyed including the text in the next room, which is supposed to still be present.

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

17 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

Related Questions

Tex Prefab not showing on GameView 1 Answer

How do I instantiate a textObject prefab? 0 Answers

Help making a damage number system 1 Answer

Prefabs not visible in webplayer? (read from .txt file) 1 Answer

Why is transform.position of a prefab that's been instantiated different than a gameobject created on the scene, when they are in the exact same position? 1 Answer


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