mirror of
https://github.com/kuhyx/praca_magisterska.git
synced 2026-07-04 15:43:14 +02:00
24 lines
589 B
C#
24 lines
589 B
C#
using UnityEngine;
|
|
|
|
public class Bullet : MonoBehaviour
|
|
{
|
|
public float speed = 10f;
|
|
|
|
void Update()
|
|
{
|
|
transform.Translate(Vector3.up * speed * Time.deltaTime);
|
|
if (transform.position.y > 10) Destroy(gameObject); // Out of bounds
|
|
}
|
|
|
|
void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
Debug.Log($"Bullet hit: {other.name} with tag: {other.tag}");
|
|
if (other.gameObject.GetComponent<Enemy>() != null)
|
|
{
|
|
Debug.Log("Enemy destroyed!");
|
|
Destroy(other.gameObject);
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|