예제 #1
0
 /// <summary>
 /// 当子弹碰撞到物体,停止运动
 /// </summary>
 public override void CollisionEnter(Collision collision)
 {
     Debug.Log("Stop");
     //子弹停止运动
     M_Rigidbody.Sleep();
     //生成弹痕
     if (collision.collider.GetComponent <BulletMarks>() != null)
     {
         if (Physics.Raycast(ray, out hit, 1000, 1 << 11))
         {
         }
         //调用里面的方法
         collision.collider.GetComponent <BulletMarks>().CreateBulletMark(hit);
         collision.collider.GetComponent <BulletMarks>().Hp -= Demage;
     }
     if (collision.collider.GetComponentInParent <AI>() != null)
     {
         if (Physics.Raycast(ray, out hit, 1000, 1 << 12))
         {
         }
         //调用里面的方法
         //collision.collider.GetComponentInParent<AI>().HP -= Demage;
         collision.collider.GetComponentInParent <AI>().PlayFleshEffect(hit);
         if (collision.collider.gameObject.name == "Head")
         {
             collision.collider.GetComponentInParent <AI>().HeadHit(Demage * 2);
         }
         else
         {
             collision.collider.GetComponentInParent <AI>().NormalHit(Demage);
         }
     }
     Destroy(gameObject);
 }
예제 #2
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);
    }
예제 #3
0
    public override void CollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag != "Arrow")
        {
            //箭头停止运动
            M_Rigidbody.Sleep();
            //如果碰到了障碍物
            if (collision.collider.gameObject.layer == LayerMask.NameToLayer("Env"))
            {//计算伤害
                collision.collider.GetComponent <BulletMarks>().Hp -= Demage;
                collision.collider.GetComponent <BulletMarks>().PlayAudio(hit);
                //移除刚体
                Destroy(M_Rigidbody);
                //移除碰撞器
                Destroy(m_BoxCollider);
                //设置父物体跟随
                M_Transform.SetParent(collision.gameObject.transform);

                StartCoroutine("TileAnimation", pivot_Transform);
            }
            if (collision.collider.gameObject.layer == LayerMask.NameToLayer("AI"))
            {//计算伤害
                collision.collider.GetComponentInParent <AI>().HP -= Demage;
                collision.collider.GetComponentInParent <AI>().PlayFleshEffect(hit);
                //移除刚体
                Destroy(M_Rigidbody);
                //移除碰撞器
                Destroy(m_BoxCollider);
                //设置父物体跟随
                M_Transform.SetParent(collision.gameObject.transform);

                StartCoroutine("TileAnimation", pivot_Transform);
            }
        }
    }
예제 #4
0
파일: Bullet.cs 프로젝트: dqtoy/CubeShoot
 public override void Shoot(Vector3 dir, int force, int damage, ObjectPool bulletPool)
 {
     trailTrans.gameObject.SetActive(true);
     M_Rigidbody.AddForce(dir * force);
     this.bulletPool = bulletPool;
     ray             = new Ray(M_Transform.position, dir);
     this.damage     = damage;
     TimerSvc.Instance.AddTimeTask((int tid) =>
     {
         taskID = tid;
         M_Rigidbody.Sleep();
         bulletPool.AddObject(gameObject);
     }, 3000);
     trailTaskID = TimerSvc.Instance.AddTimeTask((int tid) =>
     {
         trailTrans.gameObject.SetActive(false);
     }, 500);
 }
예제 #5
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);
        }
    }
예제 #6
0
    protected override void Collision(Collision coll)
    {
        M_Rigidbody.Sleep();
        if (coll.gameObject.layer == LayerMask.NameToLayer("Envionment"))
        {
            GameObject.Destroy(m_BoxCollider);
            GameObject.Destroy(M_Rigidbody);
            BulletMark tempBulletMark = coll.collider.GetComponent <BulletMark>();
            if (tempBulletMark != null)
            {
                tempBulletMark.HP -= Damage;
            }
            StartCoroutine("AnimationPlay", m_Pivot);
            M_Transform.SetParent(coll.gameObject.transform);
        }
        else if (coll.gameObject.layer == LayerMask.NameToLayer("AI"))
        {
            GameObject.Destroy(m_BoxCollider);
            GameObject.Destroy(M_Rigidbody);
            AI tempAI = coll.collider.GetComponentInParent <AI>();
            if (tempAI != null)
            {
                // 头部伤害加倍
                if (coll.collider.gameObject.name == "Head")
                {
                    tempAI.HeadGetHit(Damage);
                }
                else
                {
                    tempAI.NormalHit(Damage);
                }

                // 播放血液特效
                tempAI.PlayBloodEffect(aiEffectHit);
            }
            StartCoroutine("AnimationPlay", m_Pivot);
            M_Transform.SetParent(coll.gameObject.transform);
        }
    }
예제 #7
0
파일: Bullet.cs 프로젝트: dqtoy/CubeShoot
    public override void CollisionEnter(Collision collision)
    {
        PECommon.Log("碰到物体的名字是:" + collision.collider.transform.name);
        M_Rigidbody.Sleep();
        TimerSvc.Instance.RemoveTake(taskID);
        taskID = -10;
        TimerSvc.Instance.RemoveTake(trailTaskID);
        trailTaskID = -100;
        TimerSvc.Instance.AddTimeTask((int tid) =>
        {
            bulletPool.AddObject(gameObject);
        }, 500);
        if (collision.collider.GetComponent <BulletMark>() != null)
        {
            if (Physics.Raycast(ray, out hit, 1000, ~(1 << 10)))
            {
            }
            collision.collider.GetComponent <BulletMark>().CreateBulletMark(hit);
        }
        GameObject targetPlayer = UnityTools.FindUpParent(collision.collider.transform).gameObject;

        if (targetPlayer.tag == "Player")
        {
            Vector3   hitPos     = collision.collider.transform.position;
            MyVector3 hitPosMyV3 = UnityTools.GetMyV3Value(hitPos);
            PECommon.Log("射中的目标最上层物体的名字:" + UnityTools.FindUpParent(collision.collider.transform).gameObject.name);
            //----------------------------------
            if (targetPlayer.GetComponent <ControllerBase>() == null)
            {
                return;
            }
            //别射到自己。
            RoleType targetPlayerRoleType = targetPlayer.GetComponent <ControllerBase>().roleType;
            if (casterRoleType == targetPlayerRoleType)
            {
                return;
            }
            int hurt = 0;
            switch (collision.collider.gameObject.tag)
            {
            case "Arm":
                hurt = damage / 2;
                PECommon.Log("造成肢体伤害" + hurt);
                break;

            case "Body":
                hurt = damage;
                PECommon.Log("造成身体伤害" + hurt);
                break;

            case "Head":
                hurt = damage * 2;
                PECommon.Log("造成头部伤害" + hurt);
                break;
            }

            //发送网络消息
            GameMsg gameMsg = new GameMsg
            {
                cmd           = (int)CMD.ReqTakeDamage,
                reqTakeDamage = new ReqTakeDamage
                {
                    damageID       = damageID,
                    casterRoleType = casterRoleType,
                    targetRoleType = targetPlayerRoleType,
                    hurt           = hurt,
                    hitPos         = hitPosMyV3,
                },
            };

            netSvc.SendMsg(gameMsg);
            //准星变红
            if (casterRoleType == BattleSys.Instance.GetCurrentRoleType())
            {
                BattleSys.Instance.SetSignRed();
            }
        }
        gameObject.SetActive(false);
    }