Advertisement
GigaOrts

Collectable

Jun 29th, 2025
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.47 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Collectable : MonoBehaviour
  4. {
  5.     public GameObject fruit;
  6.     public GameObject animation;
  7.     public AudioClip sound;
  8.    
  9.     private void OnTriggerEnter2D(Collider2D other)
  10.     {
  11.         if (other.CompareTag("Player"))
  12.         {
  13.             fruit.SetActive(false);
  14.             animation.SetActive(true);
  15.             AudioSource.PlayClipAtPoint(sound, transform.position);
  16.             Destroy(other.gameObject);
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement