- Home /
Destroy Object On Touch? 2D
Hello, I am making a game where part of it you have to tap the right square "Object" to proceed. I thought it would be simple to just code it but then again I am considered a noob when it comes to scripting. All help is appreciated.
Some info on what I want- The game is 2D, I want the object to be destroyed instantly when tapped on.
Answer by pako · Feb 09, 2015 at 08:40 AM
Make sure you have a collider on your square object, e.g. BoxCillider2D
Attach the following script on the square object:
using UnityEngine;
public class KillSquare : MonoBehaviour {
void OnMouseDown() { Destroy(this.gameObject); } }
It will work as you want.
It's considered good practice in this forum to accept an answer that has helped you (click the check-mark icon below the down-vote icon). It's also good practice to up-vote the answers and comments that you have found are especially useful.
Your answer
Follow this Question
Related Questions
Destroy Object On Touch? 4 Answers
Duplication Problem. Please help. 2 Answers
Why won't the Score reset? 2 Answers
Game looks different on device compared to Game View 0 Answers
Reset Score after game is finished? 2 Answers