smart-interactive-display/Assets/GadGame/Scripts/MiniGame/Item.cs

53 lines
1.4 KiB
C#
Raw Normal View History

2024-04-16 03:23:44 -07:00
using DG.Tweening;
2024-04-15 04:10:00 -07:00
using GadGame.Manager;
using Pools.Runtime;
using UnityEngine;
namespace GadGame.MiniGame
{
public class Item : MonoBehaviour, ICollect, IPoolable
2024-04-15 04:10:00 -07:00
{
[SerializeField] private int _score;
2024-04-15 20:57:02 -07:00
[SerializeField] private Rigidbody2D _rb;
2024-04-22 00:09:55 -07:00
[SerializeField] private Pool<ParticleObject> _hitEffect;
private bool _inUsed;
2024-04-16 03:23:44 -07:00
private Tweener _tweener;
2024-04-15 20:57:02 -07:00
public void Init(float gravityScale = 1)
{
_rb.gravityScale = gravityScale;
2024-04-16 03:23:44 -07:00
_tweener = transform.DORotate(new Vector3(0, 0, gravityScale * 50),0.1f).SetLoops(-1, LoopType.Incremental);
2024-04-15 20:57:02 -07:00
}
private void LateUpdate()
{
if (_inUsed && _rb.position.y <= -10)
2024-04-15 20:57:02 -07:00
{
this.Release();
}
}
2024-04-15 04:10:00 -07:00
public void Collect()
{
GameManager.Instance.UpdateScore(_score);
SoundManager.Instance.PlaySfx(SoundDefine.CollectStar);
2024-04-22 00:09:55 -07:00
var fx = _hitEffect.Get();
fx.transform.position = transform.position;
2024-04-15 04:10:00 -07:00
this.Release();
}
public void OnGet()
{
_inUsed = true;
}
public void OnRelease()
{
_inUsed = false;
2024-04-16 03:23:44 -07:00
_tweener.Restart();
_tweener.Complete();
_tweener.Kill();
}
2024-04-15 04:10:00 -07:00
}
}