Tugas-Akhir-Game-Edukasi-Ma.../Assets/Projectileboss.cs

38 lines
890 B
C#

using UnityEngine;
public class Projectileboss : MonoBehaviour
{
public float lifetime = 5f;
public float damage = 10f; // Damage yang diberikan ke player
private Rigidbody2D rb;
void Start()
{
Destroy(gameObject, lifetime);
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
if (rb != null && rb.velocity != Vector2.zero)
{
float angle = Mathf.Atan2(rb.velocity.y, rb.velocity.x) * Mathf.Rad2Deg - 90f;
transform.rotation = Quaternion.Euler(0f, 0f, angle);
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
IDamageable player = other.GetComponent<IDamageable>();
if (player != null)
{
player.TakeDamage(damage);
}
Destroy(gameObject);
}
}
}