fgm24/Assets/Scripts/Enemy/EnemyProjectile.cs

26 lines
595 B
C#
Raw Normal View History

2024-02-03 01:41:20 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyProjectile : MonoBehaviour
{
2024-02-03 03:28:29 +01:00
private Transform target;
2024-02-03 01:41:20 +01:00
public float speed = 5f;
public float projectileLifetime = 3f;
Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
2024-02-03 03:28:29 +01:00
2024-02-03 01:41:20 +01:00
}
void FireProjectile()
{
Vector2 directionToTarget = (target.transform.position - transform.position).normalized;
rb.velocity = directionToTarget * speed;
Destroy(this, projectileLifetime);
}
}