Created
October 27, 2023 20:38
-
-
Save TheMehranKhan/ab9ec4bf89e89e48843f15c06cee2493 to your computer and use it in GitHub Desktop.
A collectible item that gives points to the player's score when the player collides with it.
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
// Author: themehrankhan | |
using UnityEngine; | |
/// <summary> | |
/// A collectible item that gives points to the player's score when the player collides with it. | |
/// </summary> | |
public class CollectibleItem : MonoBehaviour | |
{ | |
/// <summary> | |
/// The number of points that the collectible item gives to the player. | |
/// </summary> | |
public int points = 10; | |
void OnTriggerEnter(Collider other) | |
{ | |
/// <summary> | |
/// Checks if the collectible item collided with the player. | |
/// </summary> | |
/// <param name="other">The collider that collided with the collectible item.</param> | |
if (other.CompareTag("Player")) | |
{ | |
// Get the player's ScoreManager component. | |
ScoreManager scoreManager = other.GetComponent<ScoreManager>(); | |
// Add points to the player's score. | |
scoreManager.AddScore(points); | |
// Destroy the collectible item. | |
Destroy(gameObject); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment