44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Pool;
|
|
|
|
namespace BlueWater.Tycoons
|
|
{
|
|
public class Liquid : LiquidIngredient
|
|
{
|
|
[SerializeField]
|
|
private float _autoDestroyTime = 2f;
|
|
|
|
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);
|
|
|
|
Invoke(nameof(ReachedObject), _autoDestroyTime);
|
|
}
|
|
|
|
public void SetManagedPool(IObjectPool<Liquid> pool) => _managedPool = pool;
|
|
|
|
public void Destroy()
|
|
{
|
|
CancelInvoke(nameof(ReachedObject));
|
|
_managedPool.Release(this);
|
|
}
|
|
|
|
public override void ReachedObject()
|
|
{
|
|
base.ReachedObject();
|
|
|
|
CanInteraction = false;
|
|
Destroy();
|
|
}
|
|
}
|
|
} |