CapersProject/Assets/02.Scripts/Tycoon/Garnish.cs

43 lines
1.3 KiB
C#
Raw Normal View History

2024-09-24 10:35:49 +00:00
using UnityEngine;
using UnityEngine.Pool;
namespace BlueWater.Tycoons
{
public class Garnish : LiquidIngredient
{
2024-11-17 14:21:16 +00:00
[SerializeField]
private float _autoDestroyTime = 2f;
2024-09-24 10:35:49 +00:00
private IObjectPool<Garnish> _managedPool;
2024-12-02 11:43:08 +00:00
public void Initialize(Vector3 spawnPosition, Quaternion rotation, Collider2D targetCollider, Vector3 pushForce, Sprite sprite)
2024-09-24 10:35:49 +00:00
{
transform.position = spawnPosition;
transform.rotation = rotation;
TargetCollider = targetCollider;
2024-12-02 11:43:08 +00:00
SpriteRenderer.sprite = sprite;
2024-09-24 10:35:49 +00:00
Rigidbody2D.linearVelocity = Vector2.zero;
CanInteraction = true;
gameObject.SetActive(true);
Rigidbody2D.AddForce(pushForce, ForceMode2D.Impulse);
2024-11-17 14:21:16 +00:00
Invoke(nameof(ReachedObject), _autoDestroyTime);
2024-09-24 10:35:49 +00:00
}
public void SetManagedPool(IObjectPool<Garnish> pool) => _managedPool = pool;
2024-11-17 14:21:16 +00:00
public void Destroy()
{
CancelInvoke(nameof(ReachedObject));
_managedPool.Release(this);
}
2024-09-24 10:35:49 +00:00
public override void ReachedObject()
{
2024-11-17 14:21:16 +00:00
base.ReachedObject();
2024-09-24 10:35:49 +00:00
CanInteraction = false;
Destroy();
}
}
}