31 lines
564 B
C#
31 lines
564 B
C#
using UnityEngine;
|
|
|
|
public class Projectile : MonoBehaviour
|
|
{
|
|
[SerializeField] private Rigidbody2D rb;
|
|
public int damage;
|
|
public float speed;
|
|
public float lifetime;
|
|
public Vector2 direction;
|
|
|
|
|
|
private void Start()
|
|
{
|
|
Destroy(gameObject, lifetime);
|
|
direction = transform.right;
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
rb.linearVelocity = direction * speed;
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
if (!other.CompareTag(tag) && other.TryGetComponent(out Entity isEntity))
|
|
{
|
|
isEntity.TakeDamage(damage);
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|