Qu/Assets/Scripts/Bullet.cs
Gerard Gascón bd5b1556ff init
2025-04-24 14:23:29 +02:00

22 lines
504 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour{
public float speed;
Rigidbody2D rb2d;
void Start(){
rb2d = GetComponent<Rigidbody2D>();
rb2d.AddRelativeForce(Vector2.right * speed, ForceMode2D.Impulse);
}
void OnCollisionEnter2D(Collision2D col){
if(col.gameObject.tag == "Dragon"){
FindObjectOfType<Dragon>().TakeDamage(5);
}
Destroy(gameObject);
}
}