37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using UnityEngine;
|
|
using UnityEngine.VFX;
|
|
|
|
using RR.Common.Interfaces;
|
|
using RR.Common.Audio;
|
|
using RR.Game2D.Core.Managers;
|
|
|
|
namespace RR.Common.Entities.Props
|
|
{
|
|
[RequireComponent(typeof(Collider2D))]
|
|
public class Collectible : MonoBehaviour, IPickable
|
|
{
|
|
[SerializeField] private SoundEffect pickupSFX;
|
|
[SerializeField] private VisualEffect pickupVFX;
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
if (other.CompareTag("Player")) TryPickup(other.gameObject);
|
|
}
|
|
|
|
public virtual bool TryPickup(GameObject newOwner, Transform optionalAttachPoint = null)
|
|
{
|
|
if (pickupSFX.sound != null)
|
|
GameManager.Instance.Audio.PlaySfxAt(pickupSFX.sound, transform.position,
|
|
pickupSFX.volume, pickupSFX.pitch);
|
|
|
|
if (pickupVFX != null)
|
|
{
|
|
pickupVFX.transform.position = transform.position;
|
|
pickupVFX.Play();
|
|
pickupVFX.Stop();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
} |