using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Explosi : MonoBehaviour
{
public float bao=600.0f;//爆炸的力
public GameObject go;//爆炸特效预制体
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
float radius = 300.0f;//爆炸半径
Vector3 explosionPos = transform.position;//爆炸位置
Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);
foreach (Collider hit in colliders)
{
if (hit.GetComponent<Rigidbody>())
{
hit.GetComponent<Rigidbody>().AddExplosionForce(bao, explosionPos, radius);
Instantiate(go);//爆炸特效
}
Destroy(gameObject);
}
}
}
}