Unity中的爆炸力

来源:互联网 发布:c语言if并列多个条件 编辑:程序博客网 时间:2024/05/05 10:33
    void OnCollisionEnter()
    {
        //获取爆炸范围的所有碰撞器
        Collider[] col = Physics.OverlapSphere(transform.position, explosionRadius,lm);
        if(col.Length>0) //如果有的话
        {
            for(int i=0;i<col.Length;i++)
            {   //获取刚体
                Rigidbody b = col[i].GetComponent<Rigidbody>();
                if(b!=null) //如果该物体有刚体的话
                {
                    //添加爆炸力场
                    b.AddExplosionForce(explosionForce, transform.position, explosionRadius);
                }
                unit u = col[i].GetComponent<unit>();
                if(u!=null)
                {
                    u.ApplyDamage(atk);
                }
                
            }
        }
    }
0 0