Advertisement
johnnygoodguy2000

pickupPpoints.cs

Apr 7th, 2024 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class pickupPoints : MonoBehaviour
  6. {
  7.     public int scoreToGive;
  8.  
  9.     private ScoreManager theScoreManager;
  10.  
  11.     private AudioSource coinSound;
  12.  
  13.     // Start is called before the first frame update
  14.     void Start()
  15.     {
  16.         theScoreManager = FindObjectOfType<ScoreManager>();
  17.  
  18.         coinSound = GameObject.Find("CoinSound").GetComponent<AudioSource>();
  19.     }
  20.  
  21.     // Update is called once per frame
  22.     void Update()
  23.     {
  24.        
  25.     }
  26.  
  27.     void OnTriggerEnter2D(Collider2D other)
  28.     {
  29.         if (other.gameObject.name == "Player")
  30.         {
  31.             theScoreManager.AddScore(scoreToGive);
  32.             gameObject.SetActive(false);
  33.  
  34.  
  35.             if (coinSound.isPlaying)
  36.             {
  37.                 coinSound.Stop();
  38.                 coinSound.Play();
  39.             }
  40.  
  41.             else
  42.             {
  43.                 coinSound.Play();
  44.             }
  45.  
  46.            
  47.         }
  48.     }
  49. }
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement