This commit is contained in:
杨号敬 2024-11-27 10:57:32 +08:00
parent 9c45a3df58
commit 8ff6bb5746
4 changed files with 41 additions and 16 deletions

View File

@ -4,7 +4,7 @@ using UnityEngine;
public class Bomb : MonoBehaviour
{
public int harm;
public float harm;
public GameObject bomb;
public float explosionRadius = 5f; // 爆炸半径
public float maxDamage = 100f; // 最大伤害
@ -23,15 +23,29 @@ public class Bomb : MonoBehaviour
float damage = Mathf.Lerp(maxDamage, 0, distance / explosionRadius);
//具体伤害
if(collider.gameObject.tag=="enemy")
{
Enemy enemy = collider.gameObject.GetComponent<Enemy>();
enemy.EnemyHpDown(damage);
DesSelf();
}
if (collider.gameObject.tag == "ore")
{
Ore ore = collider.gameObject.GetComponent<Ore>();
ore.OreHpDown(damage);
DesSelf();
}
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Player"))
{
Explode();
}
Explode();
}
void DesSelf()
{
//±¬Õ¨ÌØЧ
Destroy(this.gameObject);
}
}

View File

@ -7,7 +7,7 @@ public class Bullet : MonoBehaviour
public int harm;
private void Start()
{
Destroy(this.gameObject,1f);
DesSelf(1f);
}
private void OnCollisionEnter(Collision collision)
{
@ -15,16 +15,27 @@ public class Bullet : MonoBehaviour
{
Enemy enemy = collision.gameObject.GetComponent<Enemy>();
enemy.EnemyHpDown(harm);
Destroy(this.gameObject);
DesSelf();
}
if (collision.gameObject.CompareTag("ore"))
{
Ore ore = collision.gameObject.GetComponent<Ore>();
ore.OreHpDown(harm);
Destroy(this.gameObject);
DesSelf();
}
}
void DesSelf()
{
//±¬Õ¨ÌØЧ
Destroy(this.gameObject);
}
void DesSelf(float time)
{
//±¬Õ¨ÌØЧ
Destroy(this.gameObject, time);
}
}

View File

@ -6,7 +6,7 @@ using UnityEngine.AI;
public class Enemy : MonoBehaviour
{
public NavMeshAgent _agent;
public int bloodvolume;
public float bloodvolume;
public Transform player;
// Start is called before the first frame update
void Start()
@ -27,7 +27,7 @@ public class Enemy : MonoBehaviour
}
}
public void EnemyHpDown(int hp)
public void EnemyHpDown(float hp)
{
bloodvolume -= hp;
}

View File

@ -4,14 +4,14 @@ using UnityEngine;
public class Ore : MonoBehaviour
{
public int OreHp;
public float OreHp;
// Start is called before the first frame update
void Start()
{
}
public void OreHpDown(int hp)
public void OreHpDown(float hp)
{
if (OreHp <=0) return;
OreHp-=hp;