Example #1
0
    protected override void CollisionEnter(Collision other)
    {
        M_Rigidbody.Sleep();

        BulletMark bulletMark = other.gameObject.GetComponent <BulletMark>();
        AIBase     ai         = other.gameObject.GetComponentInParent <AIBase>();

        // 攻击环境物体.
        if (bulletMark != null)
        {
            bulletMark.CreateBulletMark(hit);
            bulletMark.Hp -= Damage;
        }

        // 攻击AI角色.
        else if (ai != null)
        {
            // 头部伤害加倍.
            if (other.gameObject.name == "Head")
            {
                ai.Life -= 2 * Damage;
                ai.HitHeadState();
            }
            else
            {
                ai.Life -= Damage;
                ai.HitNormalState();
            }

            ai.PlayEffect(hit);
        }

        gameObject.SetActive(false);
    }
Example #2
0
    /// <summary>
    ///  碰撞时执行的方法
    /// </summary>
    /// <param name="coll"></param>
    protected override void Collision(Collision coll)
    {
        M_Rigidbody.Sleep();
        /// 和环境交互
        if (coll.gameObject.layer == LayerMask.NameToLayer("Envionment"))
        {
            BulletMark bulletMark = coll.gameObject.GetComponent <BulletMark>();
            if (bulletMark != null)
            {
                bulletMark.CreateBulletMark(uiHit);
                bulletMark.HP -= Damage;
            }
            GameObject.Destroy(gameObject);
        }
        /// 和 AI 交互
        else if (coll.gameObject.layer == LayerMask.NameToLayer("AI"))
        {
            AI tempAI = coll.collider.GetComponentInParent <AI>();
            if (tempAI != null)
            {
                // 头部伤害加倍
                if (coll.collider.gameObject.name == "Head")
                {
                    tempAI.HeadGetHit(Damage);
                }
                else
                {
                    tempAI.NormalHit(Damage);
                }



                tempAI.PlayBloodEffect(aiHit);
            }
            GameObject.Destroy(gameObject);
        }
        else
        {
            GameObject.Destroy(gameObject, 2.0f);
        }
    }
Example #3
0
    /// <summary>
    /// 射击.
    /// </summary>
    protected override void Shoot()
    {
        if (hit.point != Vector3.zero)
        {
            BulletMark bulletMark = hit.collider.GetComponent <BulletMark>();
            AIBase     ai         = hit.collider.GetComponentInParent <AIBase>();

            // 射击到环境物体.
            if (bulletMark != null)
            {
                bulletMark.CreateBulletMark(hit);
                bulletMark.Hp -= Damage;
            }

            // 攻击AI角色.
            else if (ai != null)
            {
                // 头部伤害加倍.
                if (hit.collider.gameObject.name == "Head")
                {
                    ai.Life -= 2 * Damage;
                    ai.HitHeadState();
                }
                else
                {
                    ai.Life -= Damage;
                    ai.HitNormalState();
                }

                ai.PlayEffect(hit);
            }
        }
        else
        {
            GameObject.Instantiate <GameObject>(m_AssaultRifleView.Prefab_Bullet,
                                                hit.point, Quaternion.identity);
        }

        Durable--;
    }