26 lines
595 B
C#
26 lines
595 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class EnemyProjectile : MonoBehaviour
|
|
{
|
|
private Transform target;
|
|
public float speed = 5f;
|
|
public float projectileLifetime = 3f;
|
|
Rigidbody2D rb;
|
|
void Start()
|
|
{
|
|
rb = GetComponent<Rigidbody2D>();
|
|
}
|
|
private void Update()
|
|
{
|
|
|
|
}
|
|
void FireProjectile()
|
|
{
|
|
Vector2 directionToTarget = (target.transform.position - transform.position).normalized;
|
|
rb.velocity = directionToTarget * speed;
|
|
Destroy(this, projectileLifetime);
|
|
}
|
|
}
|