ReisenYoumuOuting/Assets/Scripts/Projectiles/Projectile.cs

32 lines
578 B
C#

using System;
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);
}
}
}