Download examples/open_world_city/Assets/Scripts/PickupSystem.cs from ryzerrr/unity-game-agent: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/ryzerrr/unity-game-agent/resolve/main/examples/open_world_city/Assets/Scripts/PickupSystem.cs
- Command line
-
hf download hf://ryzerrr/unity-game-agent/examples/open_world_city/Assets/Scripts/PickupSystem.cs
-
curl -L -o PickupSystem.cs https://huggingface.co/ryzerrr/unity-game-agent/resolve/main/examples/open_world_city/Assets/Scripts/PickupSystem.cs
1.83 kB
| using UnityEngine; | |
| using UnityEngine.Events; | |
| namespace UnityAgent | |
| { | |
| /// <summary> | |
| /// Collectible pickup. Triggers an event when collected and adds to the | |
| /// global PickupSystem score. | |
| /// </summary> | |
| [] | |
| public class Pickup : MonoBehaviour | |
| { | |
| public int value = 10; | |
| public AudioClip collectClip; | |
| public UnityEvent onCollected; | |
| private void Reset() | |
| { | |
| GetComponent<Collider>().isTrigger = true; | |
| } | |
| private void OnTriggerEnter(Collider other) | |
| { | |
| if (!other.CompareTag("Player")) return; | |
| PickupSystem.Instance?.Collect(value); | |
| onCollected?.Invoke(); | |
| if (collectClip != null && PickupSystem.Instance != null) | |
| PickupSystem.Instance.PlayPickupSound(collectClip); | |
| Destroy(gameObject); | |
| } | |
| } | |
| /// <summary> | |
| /// Singleton that tracks the player's score and plays pickup sounds. | |
| /// </summary> | |
| public class PickupSystem : MonoBehaviour | |
| { | |
| public static PickupSystem Instance { get; private set; } | |
| public int score { get; private set; } | |
| public AudioSource audioSource; | |
| public System.Action<int> onScoreChanged; | |
| private void Awake() | |
| { | |
| if (Instance != null && Instance != this) { Destroy(gameObject); return; } | |
| Instance = this; | |
| if (audioSource == null) audioSource = gameObject.AddComponent<AudioSource>(); | |
| } | |
| public void Collect(int amount) | |
| { | |
| score += amount; | |
| onScoreChanged?.Invoke(score); | |
| } | |
| public void PlayPickupSound(AudioClip clip) | |
| { | |
| if (audioSource != null && clip != null) audioSource.PlayOneShot(clip); | |
| } | |
| } | |
| } | |