- Home /
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
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
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?
Please don't create multiple questions for the same thing.
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);
}`
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
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
Follow this Question
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