Source file unity-csharp/ebook/CoinPickupFeedback.cs from the GDnD code examples. Download raw file
// Demonstrates event-linked pickup feedback for The Architecture of Play ebook.
// Referenced by: docs/ebook/GDnD-Architecture-of-Play.md
using UnityEngine;
public class CoinPickupFeedback : MonoBehaviour
{
[SerializeField] private AudioSource audioSource;
[SerializeField] private ParticleSystem pickupParticles;
[SerializeField] private SpriteRenderer spriteRenderer;
public void Play()
{
if (spriteRenderer != null)
{
spriteRenderer.enabled = false;
}
if (pickupParticles != null)
{
pickupParticles.Play();
}
if (audioSource != null)
{
audioSource.Play();
}
Destroy(gameObject, 0.5f);
}
}