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 derrtyones · Aug 28, 2012 at 01:40 PM · javascriptdestroyimage

Destroy box and show image

Hi,

I got the following situation. There's a box on my scene. If the player touches the box, the box will be deleted and an image has to appear on the screen.

So when I play the game and touch the box, the box will be destroyed but the image won't appear on the screen. However, if I take out the line to destroy the box, it does work. But I need the box removed too!

This is my script right now:

 var show : boolean;
 var GUI_Key : Texture2D;
 
 function Start(){
     show = false;
 }
 
 function OnTriggerEnter (other : Collider) {
     
     //Get the item by touching it, then destroy the item
     Destroy(gameObject);
     
     //Put item image on screen
     show = true;
 }
 
 function OnGUI () {
     if(show){
         GUI.DrawTexture(new Rect(10,10,40,39), GUI_Key);
     }
 }
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
0
Best Answer

Answer by Mander · Aug 28, 2012 at 02:44 PM

u destroy the object with the script. so it won't run the script after u destroy it. attach the gui scrpit on an emptygame object or on ur gui object but leave ur destrooy function on that cube. and before u destroy it change the variable on ur gui script.

 function OnTriggerEnter (other : Collider) {
 gameObject.Find("GuiObject").GetComponent("guiscript").show = true;
 Destroy(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
1
Wiki

Answer by Karsnen_2 · Aug 28, 2012 at 02:12 PM

Which gameobject are you destroying? Are you destroying the gameobject which has the GUI Texture as its own component?

Comment
Add comment · Show 6 · 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 derrtyones · Aug 28, 2012 at 02:17 PM 0
Share

I am destroying the gameobject that I touch, which is a simple box with the name Cube_$$anonymous$$ey. The script is attached to this gameobject. I think the GUI Texture is seperated.

avatar image Karsnen_2 · Aug 28, 2012 at 02:23 PM 1
Share

Derrtyones. When you happen to destroy the gameobject, try to pause the game on the editor and check whether the required GUI Text component is present on the hierarchy panel.

avatar image derrtyones · Aug 28, 2012 at 02:28 PM 0
Share

Ok I noticed that when the box is destroyed, all that disappears is the "Cube_$$anonymous$$ey" object in the Hierarchy, which is the object that I touch. When I select the Cube_$$anonymous$$ey object and look at the script section in the inspector, I do see: "GUI_$$anonymous$$ey" and it shows the image behind it. By the way, I am quite new to this all.

avatar image Karsnen_2 · Aug 28, 2012 at 02:33 PM 1
Share

So I am glad that you have found the mistake. Do feel bad that you are new, everyone have crossed your path and we are here to help you.

avatar image derrtyones · Aug 28, 2012 at 02:37 PM 0
Share

Well thank you but I am not sure how to solve this. How can I fix this?

Show more comments

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

9 People are following this question.

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

Related Questions

Find Keyword in a Searched GameObject (JS) 2 Answers

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Is it possible to destroy an object at a specific position? 2 Answers

Co Routine 2 Answers

How to Display Map 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