BGJ-2022.1/Assets/Scripts/AI/Projectile.cs

46 lines
1012 B
C#

using Pausable;
using UnityEngine;
namespace AI
{
[RequireComponent(typeof(Rigidbody2D))]
public class Projectile : MonoBehaviour, IPausable
{
[SerializeField] protected float damageOnContact = 50f;
private Rigidbody2D _rigidbody = null;
private void Awake()
{
_rigidbody = GetComponent<Rigidbody2D>();
}
public void SetVelocity(Vector2 velocity)
{
_rigidbody.velocity = velocity;
}
private void OnCollisionEnter2D(Collision2D other)
{
ProjectilePool.Instance.Return(this);
}
public bool IsPaused { get; protected set; } = false;
public void Pause()
{
IsPaused = true;
UpdateRigidbody();
}
public void Resume()
{
IsPaused = false;
UpdateRigidbody();
}
private void UpdateRigidbody()
{
_rigidbody.simulated = !IsPaused;
}
}
}