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

48 lines
1.0 KiB
C#
Raw Normal View History

2022-02-22 11:25:25 +03:00
using Pausable;
using UnityEngine;
namespace AI
{
[RequireComponent(typeof(Rigidbody2D))]
public class Projectile : MonoBehaviour, IPausable
{
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);
2022-02-26 18:31:19 +03:00
if (other.transform.CompareTag("Player"))
other.gameObject.GetComponent<Player.Death>().Die();
2022-02-22 11:25:25 +03:00
}
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;
}
}
}