Exemplo n.º 1
0
 protected override void OnTriggerEnter(Collider col)
 {
     if (col.gameObject.layer == (int)ObjectLayer.Enemy || col.gameObject.layer == (int)ObjectLayer.SpecialEnemy)
     {
         if (!enemyList.Contains(col.gameObject))                //攻击存在性判断
         {
             enemyList.Add(col.gameObject);
             RealAttack = BasicAttack * AttackFactor;
             //传参给enemy告知受伤
             TransformForward = PlayerMedi.PlayerMono.transform.forward;
             EnemyHurtAttribute.ModifyAttr((int)RealAttack, VelocityForward, VelocityVertical, TransformForward);
             EnemyReturn = col.GetComponent <IEnemyMono>().Hurt(EnemyHurtAttribute);
             //特效
             InstantiateEffect();
         }
     }
 }          // end_function
Exemplo n.º 2
0
        public override void Attack()
        {
            // 子弹数计算
            if (CurrentBulletCount <= 0)
            {
                Reload();
                return;
            }
            --CurrentBulletCount;
            GameMainProgram.Instance.eventMgr.InvokeEvent(EventName.BulletCount);

            // 特效
            muzzleFlashEffect.SetActive(true);
            resourcesMgr.LoadAsset(shootEffect, true, bulletPosition.position, Quaternion.identity);
            // 子弹壳
            Vector3    randomEmptyShellForce = new Vector3(Random.Range(emptyShellMinForce.x, emptyShellMaxForce.x), Random.Range(emptyShellMinForce.y, emptyShellMaxForce.y), Random.Range(emptyShellMinForce.z, emptyShellMaxForce.z));
            GameObject emptyShell            = resourcesMgr.LoadAsset(shellEffect, true, shellPosition.position, shellPosition.rotation);

            emptyShell.GetComponent <Rigidbody>().AddForce(shellPosition.rotation * randomEmptyShellForce, ForceMode.Impulse);

            // 碰撞检测
            Ray        ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.gameObject.layer == (int)ObjectLayer.Enemy)
                {
                    RealAttack = BasicAttack * AttackFactor;
                    // 传参给enemy告知受伤
                    TransformForward = PlayerMedi.PlayerMono.transform.forward;
                    EnemyHurtAttribute.ModifyAttr((int)RealAttack, VelocityForward, VelocityVertical, TransformForward);
                    EnemyReturn = hit.transform.GetComponent <IEnemyMono>().Hurt(EnemyHurtAttribute);
                    // 特效
                    resourcesMgr.LoadAsset(bloodEffect, true, hit.point + (hit.normal * .04f), Quaternion.LookRotation(hit.normal));
                }
                else  // 打在物体上
                {
                    resourcesMgr.LoadAsset(holeEffect, true, hit.point + (hit.normal * .04f), Quaternion.LookRotation(hit.normal) * Quaternion.Euler(new Vector3(0, 0, Random.Range(0, 360))));
                    resourcesMgr.LoadAsset(hitEffect, true, hit.point + (hit.normal * .07f), Quaternion.LookRotation(hit.normal) * Quaternion.Euler(new Vector3(0, 0, Random.Range(0, 360))));
                }
            }
        }  // end_function
Exemplo n.º 3
0
 protected override void OnTriggerEnter(Collider col)
 {
     // 自行开关Trigger
     if (Rgbd.velocity.magnitude < 1)
     {
         Debug.Log("Trigger off");
         trigger.enabled = false;
         return;
     }
     if (col.gameObject.layer == (int)ObjectLayer.Enemy)
     {
         if (!enemyList.Contains(col.gameObject))//攻击存在性判断
         {
             enemyList.Add(col.gameObject);
             RealAttack = BasicAttack * AttackFactor;
             //传参给enemy告知受伤
             EnemyHurtAttribute.ModifyAttr((int)RealAttack, VelocityForward, VelocityVertical, TransformForward);
             EnemyReturn = col.GetComponent <IEnemyMono>().Hurt(EnemyHurtAttribute);
             //特效
             InstantiateEffect();
         }
     }
 }  // end_function