示例#1
0
 //左键攻击
 void pressLeftMouseButtonToAttack(GameObject enemyObj)
 {
     if (Input.GetMouseButtonUp(0))
     {
         if (enemyObj.GetComponent <Unit>() == null || selectedSoldier.GetComponent <Unit>() == null)
         {
             return;
         }
         SoldierType.Soldiers thisEnemyObj = enemyObj.GetComponent <Unit>().m_pSoldier;
         SoldierType.Soldiers mySoldier    = selectedSoldier.GetComponent <Unit>().m_pSoldier;
         int attack = mySoldier.getAttack();
         Debug.Log("attack: " + attack);
         int defense = thisEnemyObj.getDefense();
         if (defense > 0)
         {
             if (attack > defense)
             {
                 attack -= defense;
                 thisEnemyObj.setDefense(0);
             }
             else
             {
                 attack = 0;
                 thisEnemyObj.modifyDefense(-attack);
             }
         }
         thisEnemyObj.modifyHP(-attack);
         GameObject floatingTextObj = Instantiate(floatingText, enemyObj.transform.position, Quaternion.identity);
         floatingTextObj.GetComponent <TextMesh>().text = "-" + attack.ToString();
         Instantiate(bloodPS, enemyObj.transform.position, Quaternion.identity);
         int selectedSoldierType = selectedSoldier.GetComponent <Unit>().entityType;
         //攻击音效
         if (selectedSoldierType == 1 || selectedSoldierType == 2 || selectedSoldierType == 3)
         {
             SoundEffectManager.Instance.playAudio(5);
         }
         else if (selectedSoldierType == 4)
         {
             SoundEffectManager.Instance.playAudio(8);
         }
         else if (selectedSoldierType == 5 || selectedSoldierType == 7)
         {
             SoundEffectManager.Instance.playAudio(6);
         }
         else if (selectedSoldierType == 6)
         {
             SoundEffectManager.Instance.playAudio(9);
         }
         else if (selectedSoldierType == 8)
         {
             SoundEffectManager.Instance.playAudio(10);
         }
         selectedSoldier.GetComponent <Unit>().m_pSoldier.modifyCurrentMoveStep(-1);
         myCamShakeScript.shake(0.15f, 0.3f);
         //bCancelAttackMode = true;
         // actionModeName = null;
         destroyAttackArrow();
         attackEndFrame = Time.frameCount;
         //Reset();
     }
 }