Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 darkcookie · Jun 16, 2011 at 07:17 AM · guibuttondestroyenemy

how can i destroy a cube when i press a gui button???

plsplsplspls helpme im stuck!!!......ok im trying to make a script that when the enemy( a cube)with the tag of "enemy" is shoot and is about to be destroyed a GUI button pops up and asks you a question and if you answer wrong the cube doesnt die but if you answer right the cube destroys ..... i alredy got a character damage script on the cube so when the cube takes 100 damege it gets destroyed...i was thinking to make a script that when a GUI button is pressed it activates another script that destroyes the cube ....like this but this is for distance...i want when about to be destroed

link text

if theres no alternative i could use this script so when near the cube the GUI pops up...but pls help me on a destroy "enemy" script...plsplsplsspl

Comment
Add comment · Show 2
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 darkcookie · Jun 16, 2011 at 07:42 AM 0
Share

the script that would be triggered would be http://pastebin.com/g93Lpxwm

but i would cahnge the Application.LoadLevel(1) to the code to destroy the cube....this was a load levle script but is there a way to change it so i can destroy the cube?

avatar image Chris D · Jun 16, 2011 at 04:14 PM 0
Share

Please don't create multiple questions for the same thing.

1 Reply

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

Answer by naf456 · Jun 16, 2011 at 08:10 AM

you could just use the Destoy() command? I guess you have a 'if' statement for the GUI.Button,- you could just take the box as a 'Var : GameObject' and then set the 'if' statement to destroy it if the right button is pressed:

  `if(GUI.Button("Rect stuff here"))
   {
    //The cube is a varible
    Destroy(cube);
   }`

If you need something more flexible, then you can create Functions:

  `function DestroyObject(object:GameObject)
   {
      //the '5' is how long you want to delay the Destroy command
      //(it only works for the destroy command)
      Destroy(object,5);
   }
   //now declare that in the 'if' statement
   if(GUI.Button("rectangle stuff here"))
   {
      //again, cube is a varible defined elsewhere 
      DestroyObject(Cube);
   }`
Comment
Add comment · Show 3 · 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 darkcookie · Jun 16, 2011 at 09:00 AM 0
Share

so like this?

http://pastebin.com/iE3ejbBp

avatar image Joshua · Jun 16, 2011 at 11:45 AM 0
Share

Why would you have the entire function if you can just do Destoy(cube,5)? It's the most obsolete function I've ever seen.. :o

avatar image naf456 · Jun 16, 2011 at 03:58 PM 0
Share

The idea of the function is too add more functionality- so you can, say- play a sound when the cube gets destroyed- or instaiate another model. Thats what functions are for.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I destroy a GUI button when I click on it 1 Answer

Script Not counting enemy kills. 1 Answer

Need help with AI script 1 Answer

GUI Button to a GUI slider help ? 0 Answers

Turn off my GUI Box when I click a button. 3 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