CapersProject/Assets/02.Scripts/BlueWater/Tycoon/Liquid.cs

44 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 Liquid : LiquidIngredient
{
2024-11-11 02:02:24 +00:00
[SerializeField]
private float _autoDestroyTime = 2f;
2024-09-24 10:35:49 +00:00
private IObjectPool<Liquid> _managedPool;
public void Initialize(Vector3 spawnPosition, Quaternion rotation, Collider2D targetCollider, Vector3 pushForce, Color color)
{
transform.position = spawnPosition;
transform.rotation = rotation;
TargetCollider = targetCollider;
SpriteRenderer.color = color;
Rigidbody2D.linearVelocity = Vector2.zero;
CanInteraction = true;
gameObject.SetActive(true);
Rigidbody2D.AddForce(pushForce, ForceMode2D.Impulse);
2024-11-11 02:02:24 +00:00
Invoke(nameof(ReachedObject), _autoDestroyTime);
2024-09-24 10:35:49 +00:00
}
public void SetManagedPool(IObjectPool<Liquid> pool) => _managedPool = pool;
2024-11-11 02:02:24 +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-11 02:02:24 +00:00
base.ReachedObject();
2024-09-24 10:35:49 +00:00
CanInteraction = false;
Destroy();
}
}
}