x


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

more ▼

asked Jun 16 '11 at 07:17 AM

darkcookie gravatar image

darkcookie
294 16 25 32

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?

Jun 16 '11 at 07:42 AM darkcookie

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

Jun 16 '11 at 04:14 PM Chris D
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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);
  }`
more ▼

answered Jun 16 '11 at 08:10 AM

naf456 gravatar image

naf456
106 21 25 28

Jun 16 '11 at 09:00 AM darkcookie

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

Jun 16 '11 at 11:45 AM Joshua

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.

Jun 16 '11 at 03:58 PM naf456
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3811
x3418
x819
x784
x670

asked: Jun 16 '11 at 07:17 AM

Seen: 1109 times

Last Updated: Jun 16 '11 at 04:14 PM