xirang/Assets/scripts/Bullet.cs

31 lines
733 B
C#
Raw Permalink Normal View History

2024-11-26 22:01:14 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{
2024-11-27 00:06:25 +08:00
public int harm;
private void Start()
{
Destroy(this.gameObject,1f);
}
2024-11-26 22:01:14 +08:00
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("enemy"))
{
2024-11-27 00:06:25 +08:00
Enemy enemy = collision.gameObject.GetComponent<Enemy>();
enemy.EnemyHpDown(harm);
2024-11-26 22:01:14 +08:00
Destroy(this.gameObject);
}
if (collision.gameObject.CompareTag("ore"))
{
2024-11-27 00:06:25 +08:00
Ore ore = collision.gameObject.GetComponent<Ore>();
ore.OreHpDown(harm);
2024-11-26 22:01:14 +08:00
Destroy(this.gameObject);
}
2024-11-27 00:06:25 +08:00
2024-11-26 22:01:14 +08:00
}
2024-11-27 00:06:25 +08:00
2024-11-26 22:01:14 +08:00
}