Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine; // A header/namespace that lets us use UnityEngine..
- // A call called "IntersectingObjects" this will be different from case to case basis..
- // that inherits MonoBehaviour which is an API..
- public class IntersectingObjects : MonoBehaviour {
- // Create string with the public access modifier called "tagName"
- public string tagName;
- // A method in Unity to detect when objects intersect one another.
- private void OnTriggerEnter2D(Collider other)
- {
- // When the other object with the tag value of "tagName" collides
- if (other.gameObject.CompareTag(tagName))
- {
- // We destroy the gameObject that interseceted with it.
- Destroy(gameObject);
- // If you want to destroy the object you touch instead of yourself, for instance:
- // Your character is collecting a coin you could do:
- Destroy(other.gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement