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
|
|
|
|
{
|
2024-04-16 01:47:19 -07:00
|
|
|
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;
|
2024-04-16 01:47:19 -07:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2024-04-16 01:47:19 -07:00
|
|
|
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);
|
2024-04-19 03:46:17 -07:00
|
|
|
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();
|
|
|
|
}
|
2024-04-16 01:47:19 -07:00
|
|
|
|
|
|
|
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-16 01:47:19 -07:00
|
|
|
}
|
2024-04-15 04:10:00 -07:00
|
|
|
}
|
|
|
|
}
|