Advertisement
johnnygoodguy2000

CoinPickup.cs

Apr 27th, 2024 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.49 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CoinPickup : MonoBehaviour
  6. {
  7.     public int coinValue;
  8.     public AudioSource coinPickupSound;
  9.  
  10.     void OnTriggerEnter2D(Collider2D other)
  11.     {
  12.         if (other.CompareTag("Player")) // Check if the colliding object is tagged as "Player"
  13.         {
  14.             ScoreManager.AddPoints(coinValue);
  15.  
  16.             coinPickupSound.Play();
  17.             Destroy(gameObject);
  18.         }
  19.     }
  20. }
  21.  
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement