Last active
May 10, 2016 21:41
-
-
Save sabotai/f75018ff464c0a86ea1b723a416c66c6 to your computer and use it in GitHub Desktop.
Unity destroy upon collision 2D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| public class DestroyCollision : MonoBehaviour { //in the project tab of Unity, make a new "C# Script" called "DestroyCollision" | |
| public string tagName; //this will show up as an input box for the component, which can be given a tag of your choice. assign the | |
| void OnCollisionEnter2D(Collision2D myCol) { //run the following whenever a collision happens to the object attached with this script | |
| Debug.Log("Collision with " + myCol.gameObject); | |
| if (myCol.gameObject.tag == tagName) { //does the object collided with have the tag in question? | |
| Destroy(myCol.gameObject); //if so, destroy that object! | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment