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 darkal · Jan 03, 2014 at 10:18 PM · guiinstantiateprefabdestroyspawn

i need to destroy prefab clones

u can apply this script to ur camera

 #pragma strict
 
 var item1 : GameObject;
 var item2 : GameObject;
 var item3 : GameObject;
 var Item;
 
 var dropcount = 0;
 
 function Update() 
 {
     if(dropcount == 1)
     {
         Item = item1;
     }
     if(dropcount == 2)
     {
         Item = item2;
     }
     if(dropcount == 3)
     {
         Item = item3;
     }
 }
 
 function OnGUI()
 {
     if(GUI.Button(Rect(250, 250, 100, 50), "Destroy"))
     {
         Destroy(Item); 
     }
     if(GUI.Button(Rect(250, 200, 100, 50), "Spawn"))
     {
         Instantiate(Item);
     }
     if(GUI.Button(Rect(200, 150, 50, 50), "1"))
     {
         dropcount = 1;
     }
     if(GUI.Button(Rect(200, 200, 50, 50), "2"))
     {
         dropcount = 2;
     }
     if(GUI.Button(Rect(200, 250, 50, 50), "3"))
     {
         dropcount = 3;
     }
 }
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

1 Reply

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

Answer by valim · Jan 04, 2014 at 01:48 PM

I think you should put that instead of Destroy(Item);

 Destroy(GameObject.Find(item.name + " (Clone)"));

Also you can't destroy a prefab so it should give an error :)

Comment
Add comment · Show 4 · 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 darkal · Jan 04, 2014 at 07:17 PM 0
Share

ya umm that didnt even work.... heres error- destroy item.js(30,46): BCE0019: 'name' is not a member of 'Object'.

avatar image valim · Jan 04, 2014 at 07:37 PM 0
Share

I'm not used to javascript :)

 Destroy(GameObject.Find(Item.name + "(Clone)"));

and

 var Item : GameObject;

Tested.

avatar image darkal · Jan 04, 2014 at 07:44 PM 0
Share

nice! it worked do u know if theres a way 2 make it so when i do this part to make it spawn at my players location?

 if(GUI.Button(Rect(250, 200, 100, 50), "Spawn"))
         {
            Instantiate(Item);
         }
avatar image valim · Jan 04, 2014 at 08:03 PM 0
Share

Instantiate(Item, position, rotation);

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

19 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

Related Questions

How do I destroy a Instantiated UI image that is pushed on the Canvas? 2 Answers

How to spawn a 'boss' after all enemies defeated and then kill that 'boss'? 1 Answer

Instantiated object is destroyed in scene, but still logs as existing in console. 1 Answer

Object wont object get destroyed 1 Answer

How to spawn an object continually while floating vertically like a bubble 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