Pracownia-Programowania-Pro.../Assets/Scripts/DungeonGen/Bullet.cs

40 lines
626 B
C#
Raw Permalink Normal View History

2020-12-20 13:37:48 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{
public int speed;
public Rigidbody2D rb;
void Start()
2020-12-20 13:37:48 +01:00
{
rb.AddForce(transform.right * speed);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Enemy"))
{
DestroyBullet();
Debug.Log("Enemy damage taken");
}
if (other.CompareTag("Obstacle"))
{
DestroyBullet();
Debug.Log("Obstacle detected");
}
}
void OnBecameInvisible()
{
Debug.Log("Invisible bullet");
DestroyBullet();
}
void DestroyBullet()
{
Destroy(gameObject);
}
}