- Home /
Destroy object on button push?
I want my player to destroy a cube when the down arrow key is pressed on a keyboard. I know I need to use the Destroy (Object); command but what would be the entire script?
Answer by IndieScapeGames · Aug 02, 2012 at 03:42 PM
class destroyObjectScript {
void Update() {
if(Input.GetKeyDown(valueForArrowDownKey) {
Destroy(gameObject);
}
}
}
I would tell you to look up what the value for the Arrow down key is, but since it appears to be down, the IDE will probably help you auto-complete it.
I entered the script exactly as you've written it but it says there's an error. "Expecting }, got 'void'"
You're using C# script and not Java script correct?
I'm using Javascript but when I created a C# script, I got a similar error message. If I wanted that script as a Javascript, what would it look like?
if you use the code exactly as it is, it don't can work
Replace (valueForArrowDown$$anonymous$$ey) with ("down"),
here the input value http://docs.unity3d.com/Documentation/$$anonymous$$anual/Input.html
I tried that and got the same error: "Unexpected symbol: '{'"
I get similar errors and seem to be having the same problem with Javascript and C#
Answer by avidgamer · Aug 09, 2012 at 07:20 AM
thats what i get for copying the above text
class destroyObjectScript {
void Update() {
if(Input.GetKeyDown(KeyCode.DownArrow)) {
Destroy(gameObject);
}
}
}
$$anonymous$$issing a closing ) after input
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.DownArrow))
Your answer
Follow this Question
Related Questions
if object is destroyed 2 Answers
Getting all Object to go next scene. 1 Answer
Trying to Destroy Object when Wave starts 1 Answer
Destroy objects by clicking on them 1 Answer
Destroy an object with another one. 1 Answer