Enemy基类
1 /* 2 * 3 * 怪物基类,实现了怪物一些属性,死亡 4 * 5 * 6 * 7 */ 8 9 using UnityEngine; 10 using System.Collections; 11 12 13 public class Enemy : MonoBehaviour { 14 15 public GameObject IceEffect; 16 public GameObject FireEffect; 17 18 public BossType bossoneD = BossType.BossOne1;//BOSS状态 用来设置BOSS掉落 19 20 public int[] BoxDropArray = { 2, 2, 0, 0, 0, 0, 15, 21 }; 21 22 public GameObject ImpactEffect; 23 24 public string _name = "a"; //怪物名字 25 public float _maxHealth = 1; //最大生命值 26 public float _curHealth = 1; //当前生命值 27 public Transform MyTransform; 28 public EnemyType m_EnemyState = EnemyType.Null; 29 public bool _isAlive = true; //怪物是否活着 30 public float _moveSpeed=3.5f; //怪物移动速度 31 public int _rotationSpeed; //怪物旋转速度 32 public Transform _target;//目标 33 public int maxAttackDistance; //攻击距离 34 public int maxCordonDistance; //警戒距离 35 public float DeadDestoryTime; 36 public CharacterController cc; 37 public Animation MyAnimation; 38 public GameObject EnemyDrop;//掉落的物品 39 public NavMeshAgent nma;//用于存储Robot身上附带的NavMeshAgent组件 40 public int ArmorPiercingCount = 0;//穿甲弹记录 41 private float ArmorPiercingTimer = 0.0f;//穿甲弹归零记录。 42 public SenceManager m_SenceManager; 43 public bool m_CanBeAttacked = true;//可以被攻击 44 45 private bool DropGoldbl = true; 46 47 public GameObject m_GoldExp;//爆金币预设 48 public GameObject HPBar;//血条 49 50 public GameObject DeathEffect; 51 52 public bool m_ShowHpBar = false; 53 54 private bool PlayerDead; 55 56 private AudioManager m_audioManager; 57 58 void Awake() 59 { 60 m_audioManager = GameObject.FindGameObjectWithTag ("Audio").GetComponent<AudioManager> (); 61 } 62 63 public void SetShowHpBar(bool bl) 64 { 65 m_ShowHpBar = bl; 66 } 67 68 /// <summary> 69 /// 设置最大血量 70 /// </summary> 71 public void SetMaxHp(float health) 72 { 73 74 75 } 76 77 /// <summary> 78 /// 设置特效 79 /// </summary> 80 public void SetEffect() 81 { 82 83 if ((m_EnemyOnSlowDown || m_EnemyOnFrozen) && IceEffect) 84 { 85 IceEffect.SetActive(true); 86 } 87 else 88 { 89 IceEffect.SetActive(false); 90 } 91 92 if (m_EnemyOnFire && FireEffect) 93 { 94 FireEffect.SetActive(true); 95 } 96 else 97 { 98 FireEffect.SetActive(false); 99 } 100 } 101 102 103 /// <summary> 104 /// 添加敌人血条 105 /// </summary> 106 public void AddEnemyBar() 107 { 108 109 GameObject hpbar = Instantiate(HPBar, Vector3.zero, Quaternion.identity) as GameObject; 110 hpbar.SendMessage("SetTarget", this.gameObject); 111 hpbar.transform.localScale = new Vector3(1.6f, 0.5f, 0); 112 113 } 114 115 116 117 /// <summary> 118 /// 119 /// </summary> 120 public void ArmorPiercingCheck() 121 { 122 if (ArmorPiercingCount>0) 123 { 124 ArmorPiercingTimer += Time.deltaTime; 125 if (ArmorPiercingTimer>=1.5f) 126 { 127 ArmorPiercingTimer = 0; 128 ArmorPiercingCount = 0; 129 } 130 } 131 } 132 133 // Use this for initialization 134 void Start () { 135 136 AllStartInit(); 137 } 138 139 private GameObject DamageEff; 140 141 /// <summary> 142 /// 设置目标 143 /// </summary> 144 public void SetTarget(GameObject go) 145 { 146 _target = go.transform; 147 } 148 149 public GameObject player;//玩家 150 public PlayerControl m_PlayerControl; 151 152 public void AllStartInit() 153 { 154 player= GameObject.FindGameObjectWithTag("Player"); 155 156 m_PlayerControl = player.GetComponent<PlayerControl>(); 157 158 PlayerDead = m_PlayerControl.isAlive; 159 160 MyTransform = this.transform; 161 m_SenceManager = GameObject.Find("SenceManager").GetComponent<SenceManager>(); 162 cc = this.GetComponent<CharacterController>(); 163 MyAnimation = this.animation; 164 nma = GetComponent<NavMeshAgent>(); 165 i = 0; 166 167 } 168 169 private ContrlAi _curPlayer;// 170 private Vector3 InitPosition;//初始坐标 171 172 public int i = 0; 173 174 public float m_EnemyDamage; 175 176 // Update is called once per frame 177 void Update() 178 { 179 180 if (!m_PlayerControl.isAlive) 181 { 182 return; 183 } 184 185 186 187 ChildrenUpdataALL(); 188 if (_isAlive) 189 { 190 191 SetEffect(); 192 193 194 if (!_target) 195 { 196 SetTarget(player); 197 } 198 else 199 { 200 201 } 202 203 FaceToTarget(_target.gameObject); 204 Debug.DrawLine(_target.position, MyTransform.position, Color.red); 205 float DistanceWithPlayer = Vector3.Distance(player.transform.position, transform.position); 206 207 if (m_EnemyOnChaos) 208 { 209 OnChaos(); 210 } 211 else 212 { 213 if (m_EnemyOnSlowDown)//减速 214 { 215 m_SlowDownTimer += Time.deltaTime; 216 if (m_SlowDownTimer>=m_SlowDownCD) 217 { 218 m_EnemyOnSlowDown = false; 219 m_SlowDownTimer = 0.0f; 220 SlowDownLV = 0; 221 } 222 } 223 224 if (m_EnemyOnFrozen)//如果在冰冻状态 225 { 226 nma.speed = 0; 227 228 FrozenTimer += Time.deltaTime;//冰冻时间累加器 229 if (FrozenTimer>=FrozenTimeCD) 230 { 231 m_EnemyOnFrozen = false; 232 FrozenTimer = 0; 233 } 234 235 } 236 else 237 { 238 nma.speed = _moveSpeed*(1-0.2f*SlowDownLV); 239 nma.SetDestination(_target.position);//设置目的地 240 } 241 242 if (DistanceWithPlayer<=maxCordonDistance) 243 { 244 SetTarget(player); 245 if (DistanceWithPlayer<= maxAttackDistance) 246 { 247 if (damagecounti <= 0) 248 { 249 player.SendMessage("OnDamage", m_EnemyDamage); 250 _curHealth -= 1000; 251 //EnemyOnDamage(1000); 252 i++; 253 } 254 } 255 } 256 } 257 } 258 } 259 260 261 //设置最大血量 262 public void SetMaxHealth(float hp) 263 { 264 _maxHealth = hp; 265 } 266 267 /// <summary> 268 /// 面向目标 269 /// </summary> 270 /// <param name="target"></param> 271 public void FaceToTarget(GameObject target) 272 { 273 //朝向玩家 y轴不变 274 MyTransform.rotation = Quaternion.Slerp(MyTransform.rotation, Quaternion.LookRotation(new Vector3(target.transform.position.x, 0, target.transform.position.z) - new Vector3(MyTransform.position.x, 0, MyTransform.position.z)), _rotationSpeed * Time.deltaTime); 275 } 276 277 public float damageTime = 0.2f; 278 279 /// <summary> 280 /// 判断一定时间内是否受到伤害 281 /// </summary> 282 /// <returns></returns> 283 public bool isDamage() 284 { 285 bool bl = false; 286 if (damageTime <= 0) 287 { 288 bl = true; 289 } 290 else 291 { 292 bl = false; 293 } 294 return bl; 295 } 296 297 public bool m_EnemyOnChaos = false;//混乱状态 298 private float ChaosTimeCD = 5;//混乱持续时间 299 private float ChaosTimer = 0;//混乱累加器 300 301 public bool m_EnemyOnFrozen = false;//冰冻状态 302 public float FrozenTimeCD = 5;//冰冻持续时间 303 public float FrozenTimer = 0;//冰冻累加器 304 public bool m_EnemyOnSlowDown = false;//减速 305 306 public bool m_EnemyOnFire = false;//燃烧状态 307 private float FireTimeMiniCD = 1; 308 private int FireCount = 0; 309 private float FireTimer = 0; 310 311 /// <summary> 312 /// 判断计算燃烧 放在update里面 内嵌了减速判断 313 /// </summary> 314 public void Burning() 315 { 316 if (m_EnemyOnFire)//判断是否燃烧 如果燃烧 317 { 318 FireTimer += Time.deltaTime; 319 //燃烧一次 1秒掉一次血 320 if (FireTimer>=FireTimeMiniCD) 321 { 322 FireCount++; 323 FireTimer = 0; 324 EnemyOnDamage(5); 325 } 326 //如果燃烧了3次 则不在燃烧 327 if (FireCount>=3) 328 { 329 FireCount = 0;//燃烧计数重置 330 m_EnemyOnFire = false; 331 } 332 } 333 334 if (m_EnemyOnSlowDown)//减速 335 { 336 m_SlowDownTimer += Time.deltaTime; 337 if (m_SlowDownTimer >= m_SlowDownCD) 338 { 339 m_EnemyOnSlowDown = false; 340 m_SlowDownTimer = 0.0f; 341 SlowDownLV = 0; 342 } 343 } 344 345 } 346 347 /// <summary> 348 /// 判断混乱状态 放到update里面 349 /// </summary> 350 public void OnChaos() 351 { 352 //如果混乱中 353 if (m_EnemyOnChaos) 354 { 355 ChaosTimer += Time.deltaTime;//开始计时 356 SetChaosWalkPoint();//每2秒更换一次跑的地点 357 if (ChaosTimer>= ChaosTimeCD)//混乱时间到 358 { 359 ChaosTimer = 0;//时间制空 360 ChaosWalkTimer = 0.0f; 361 m_EnemyOnChaos = false;//将混乱状态置F 362 } 363 } 364 } 365 366 private float ChaosWalkCD = 1.0f; 367 private float ChaosWalkTimer = 1.0f; 368 369 /// <summary> 370 /// 每2秒设置一次混乱状态奔跑点 371 /// </summary> 372 void SetChaosWalkPoint() 373 { 374 ChaosWalkTimer += Time.deltaTime; 375 376 if (ChaosWalkTimer>=ChaosWalkCD) 377 { 378 nma.SetDestination(new Vector3(this.transform.position.x + Random.Range(-3.0f, 3.0f), this.transform.position.y,this.transform.position.z + Random.Range(-3.0f, 3.0f)));//设置目的地 379 ChaosWalkTimer = 0; 380 } 381 382 } 383 384 /// <summary> 385 /// 收到电球攻击混乱 386 /// </summary> 387 void EnemyOnElectBall() 388 { 389 m_EnemyOnChaos = true; 390 } 391 392 public int SlowDownLV = 0;//减速等级 393 public float m_SlowDownTimer = 0.0f; 394 public float m_SlowDownCD = 5.0f; 395 396 397 /// <summary> 398 /// 敌人受到减速攻击 Speed = _mySpeed*(1-0.2*SlowDownLV) 399 /// </summary> 400 void EnemyOnSlowDown() 401 { 402 m_audioManager.Enemy_Hit(); //播放怪物受击音效 403 404 m_SlowDownTimer = 0.0f;//重置减速 405 m_EnemyOnSlowDown = true;//减速 406 SlowDownLV++; 407 if (SlowDownLV >=5) 408 { 409 EnemyOnIceBall(); 410 SlowDownLV = 0; 411 m_EnemyOnSlowDown = false;//关闭减速 412 m_SlowDownTimer = 0.0f;//重置减速 413 } 414 } 415 416 /// <summary> 417 /// 受到火球攻击燃烧 418 /// </summary> 419 void EnemyOnFireBall() 420 { 421 FireCount = 0; 422 m_EnemyOnFire = true; 423 } 424 425 /// <summary> 426 /// 受到冰球攻击冰冻 427 /// </summary> 428 void EnemyOnIceBall() 429 { 430 m_EnemyOnFrozen = true; 431 } 432 433 public GameObject HPlable; 434 435 /// <summary> 436 /// 受到伤害 437 /// </summary> 438 /// <param name="damage"></param> 439 public void EnemyOnDamage(int damage) 440 { 441 if (m_CanBeAttacked && _isAlive) 442 { 443 444 GameObject goo ;//= Instantiate(ImpactEffect, MyTransform.position, MyTransform.rotation) as GameObject; 445 //求通过暴击率更改伤害值 446 PlayerControl m_PlayerControl = player.GetComponent<PlayerControl>(); 447 GameObject hplabel = Instantiate(HPlable, Vector3.zero, Quaternion.identity) as GameObject; 448 switch (m_EnemyState) 449 { 450 case EnemyType.EnemyBomb: 451 452 m_audioManager.Enemy_Hit(); //播放怪物受击音效 453 454 goo = Instantiate(ImpactEffect, MyTransform.position, MyTransform.rotation) as GameObject; 455 break; 456 case EnemyType.EnemyBomb2: 457 458 m_audioManager.Enemy_Hit(); //播放怪物受击音效 459 460 goo = Instantiate(ImpactEffect, MyTransform.position, MyTransform.rotation) as GameObject; 461 break; 462 case EnemyType.EnemyShot: 463 464 m_audioManager.Enemy_Hit(); //播放怪物受击音效 465 466 goo = Instantiate(ImpactEffect, MyTransform.position, MyTransform.rotation) as GameObject; 467 break; 468 case EnemyType.EnemyFight: 469 470 m_audioManager.Enemy_Hit(); //播放怪物受击音效 471 472 goo = Instantiate(ImpactEffect, MyTransform.position, MyTransform.rotation) as GameObject; 473 break; 474 case EnemyType.EnemyShot2: 475 476 m_audioManager.Enemy_Hit(); //播放怪物受击音效 477 478 goo = Instantiate(ImpactEffect, MyTransform.position, MyTransform.rotation) as GameObject; 479 break; 480 case EnemyType.EnemyFight2: 481 482 m_audioManager.Enemy_Hit(); //播放怪物受击音效 483 484 goo = Instantiate(ImpactEffect, MyTransform.position, MyTransform.rotation) as GameObject; 485 break; 486 case EnemyType.EnemyAOE: 487 break; 488 case EnemyType.BossOne: 489 490 //m_audioManager.Enemy_Hit(); //播放怪物受击音效 491 492 break; 493 case EnemyType.BossTwo: 494 495 //m_audioManager.Enemy_Hit(); //播放怪物受击音效 496 497 break; 498 case EnemyType.BossThree: 499 500 //sm_audioManager.Enemy_Hit(); //播放怪物受击音效 501 502 break; 503 case EnemyType.BossFour: 504 break; 505 case EnemyType.BossFive: 506 break; 507 case EnemyType.Null: 508 break; 509 case EnemyType.Enemylair: 510 break; 511 default: 512 break; 513 } 514 515 float CritRate = m_PlayerControl.CritRate; 516 float rand = Random.Range(0.01f,10.0f); 517 518 if (rand<=CritRate)//暴击 519 { 520 Vector3 vec = new Vector3(3.0f,3.0f,3.0f); 521 hplabel.SendMessage("m_SetScale", vec); 522 hplabel.GetComponent<UI_DamageLabel>().SetBaoji(); 523 hplabel.GetComponent<UILabel>().color = Color.yellow; 524 damage *= 2; 525 } 526 else 527 { 528 hplabel.GetComponent<UILabel>().color = Color.red; 529 } 530 531 hplabel.SendMessage("SetTarget", this.gameObject); 532 hplabel.SendMessage("SetValue", damage); 533 534 if (_curHealth > 0)// && isDamage()) 535 { 536 _curHealth -= damage; 537 damageTime = 0.2f; 538 } 539 540 } 541 } 542 543 public int CurrentDamage = 0; 544 545 /// <summary> 546 /// 生命限制事件 547 /// </summary> 548 public void EnemyVital() 549 { 550 #region 生命溢出限制 551 if (_curHealth > _maxHealth) 552 { 553 _curHealth = _maxHealth; 554 } 555 556 if (_curHealth <= 0) 557 { 558 _curHealth = 0; 559 _isAlive = false; 560 nma.speed = 0; 561 } 562 #endregion 563 } 564 565 public float FOWtime = 3; 566 567 /// <summary> 568 /// 子类调用的通用事件 死亡 生命限制 燃烧 569 /// </summary> 570 public void ChildrenUpdataALL() 571 { 572 573 574 575 576 FOWtime -= Time.deltaTime; 577 if (FOWtime<= 0) 578 { 579 CurrentDamage = 0; 580 FOWtime = 3; 581 } 582 damageTime -= Time.deltaTime; 583 584 DeathEvent();//死亡事件 585 EnemyVital();//生命溢出事件 586 Burning();//燃烧 587 ArmorPiercingCheck();//穿甲弹检测 588 } 589 590 591 public float DropRange ;//= 2.0f;//1~10 592 public int DropCount = 0; 593 594 public GameObject m_BombEffect; 595 596 597 int m_BombEffCount = 0; 598 int m_BombEffCount2=0; 599 int m_fight1sound=0; 600 int m_shot1sound=0; 601 int m_shot2sound=0; 602 603 //自爆怪1死亡特效 604 void BombOneEffect() 605 { 606 if (m_BombEffCount == 0) 607 { 608 m_audioManager.Bomb1_Die(); 609 610 Instantiate(m_BombEffect, this.transform.position, this.transform.rotation); 611 m_BombEffCount++; 612 } 613 } 614 615 //自爆怪2死亡特效 616 void BombTwoEffect() 617 { 618 if (m_BombEffCount2 == 0) 619 { 620 m_audioManager.Bomb2_Die(); 621 622 Instantiate(m_BombEffect, this.transform.position, this.transform.rotation); 623 m_BombEffCount2++; 624 } 625 } 626 627 //肉搏怪1死亡声音 628 void FightOneDieSound() 629 { 630 if (m_fight1sound==0) 631 { 632 m_audioManager.Fight1_Die(); 633 634 m_fight1sound++; 635 } 636 } 637 638 //射击怪1死亡声音 639 void ShotOneDieSound() 640 { 641 if (m_shot1sound==0) 642 { 643 m_audioManager.Shot1_Die(); 644 645 m_shot1sound++; 646 } 647 } 648 649 //射击怪2死亡声音 650 void ShotTwoDieSound() 651 { 652 if (m_shot2sound==0) 653 { 654 m_audioManager.Shot2_Die(); 655 656 m_shot2sound++; 657 } 658 } 659 660 661 IEnumerator m_InstantiatBombEff() 662 { 663 yield return new WaitForSeconds(5.2f); 664 Instantiate(m_BombEffect, this.transform.position, this.transform.rotation); 665 } 666 667 668 /// <summary> 669 /// 死亡事件 渐渐下落 然后销毁 670 /// </summary> 671 public void DeathEvent() 672 { 673 if (!_isAlive) 674 { 675 //碰撞器false 676 cc.enabled = false; 677 678 679 680 if (m_EnemyState == EnemyType.EnemyBomb) 681 { 682 BombOneEffect(); 683 } 684 else if(m_EnemyState == EnemyType.EnemyBomb2) 685 { 686 687 BombTwoEffect(); 688 } 689 else if (m_EnemyState==EnemyType.EnemyFight) 690 { 691 FightOneDieSound(); 692 } 693 else if (m_EnemyState==EnemyType.EnemyFight2) 694 { 695 FightOneDieSound(); 696 } 697 else if (m_EnemyState==EnemyType.EnemyShot) 698 { 699 ShotOneDieSound(); 700 } 701 else if (m_EnemyState==EnemyType.EnemyShot2) 702 { 703 ShotTwoDieSound(); 704 } 705 706 707 //PlayDeathActionOnce(); 708 this.transform.Translate(0,-0.002f,0); 709 DeadDestoryTime -= Time.deltaTime; 710 711 int RandKey = Random.Range(1,10); 712 if (DropCount<=0)//死亡后设置一次掉落 713 { 714 if (RandKey <= DropRange)//判断血瓶掉落几率 715 { 716 if (EnemyDrop)//掉落血瓶 717 { 718 Instantiate(EnemyDrop, this.transform.position, this.transform.rotation); 719 720 } 721 } 722 723 724 if (m_GoldExp && DropGoldbl) 725 { 726 DropGold(); 727 //Instantiate(m_GoldExp,this.transform.position,this.transform.rotation); 728 } 729 730 731 DropCount++; 732 } 733 734 if (DeadDestoryTime <= 0) 735 { 736 GameManager.GetInstance().m_KillCount++; 737 738 SenceSetCount(); 739 740 Destroy(this.gameObject); 741 } 742 } 743 } 744 745 746 private float m_GoldDropRang = 0;//0.1 ~ 1 747 748 private int m_GoldDropCountMin = 0;//最小值 749 750 private int m_GoldDropCountMax = 0;//最大值 751 752 753 /// <summary> 754 /// 掉落金币 755 /// </summary> 756 public void DropGold() 757 { 758 switch (m_EnemyState) 759 { 760 case EnemyType.EnemyBomb: 761 m_GoldDropRang = 0.33f; 762 m_GoldDropCountMin = 7; 763 m_GoldDropCountMax = 9; 764 break; 765 766 case EnemyType.EnemyBomb2: 767 m_GoldDropRang = 0.33f; 768 m_GoldDropCountMin = 7; 769 m_GoldDropCountMax = 9; 770 break; 771 772 case EnemyType.EnemyFight: 773 m_GoldDropRang = 0.33f; 774 m_GoldDropCountMin = 7; 775 m_GoldDropCountMax = 9; 776 break; 777 778 case EnemyType.EnemyFight2: 779 m_GoldDropRang = 0.33f; 780 m_GoldDropCountMin = 7; 781 m_GoldDropCountMax = 9; 782 break; 783 784 case EnemyType.EnemyShot: 785 m_GoldDropRang = 0.33f; 786 m_GoldDropCountMin = 7; 787 m_GoldDropCountMax = 9; 788 break; 789 790 case EnemyType.EnemyShot2: 791 m_GoldDropRang = 0.33f; 792 m_GoldDropCountMin = 7; 793 m_GoldDropCountMax = 9; 794 break; 795 796 case EnemyType.EnemyAOE: 797 m_GoldDropRang = 0.33f; 798 m_GoldDropCountMin = 7; 799 m_GoldDropCountMax = 9; 800 801 break; 802 case EnemyType.BossOne: 803 m_GoldDropRang = 1f; 804 m_GoldDropCountMin = 15; 805 m_GoldDropCountMax = 26; 806 807 break; 808 case EnemyType.BossTwo: 809 m_GoldDropRang = 1f; 810 811 m_GoldDropCountMin = 15; 812 m_GoldDropCountMax = 26; 813 break; 814 815 case EnemyType.BossThree: 816 m_GoldDropRang = 1f; 817 818 m_GoldDropCountMin = 15; 819 m_GoldDropCountMax = 26; 820 break; 821 case EnemyType.BossFour: 822 823 m_GoldDropRang = 1f; 824 m_GoldDropCountMin = 15; 825 m_GoldDropCountMax = 26; 826 827 break; 828 case EnemyType.BossFive: 829 830 m_GoldDropRang = 1f; 831 m_GoldDropCountMin = 15; 832 m_GoldDropCountMax = 26; 833 834 break; 835 case EnemyType.Null: 836 837 break; 838 case EnemyType.Enemylair: 839 840 m_GoldDropRang = 1f; 841 m_GoldDropCountMin = 3; 842 m_GoldDropCountMax = 6; 843 break; 844 default: 845 break; 846 } 847 848 float rdm = Random.Range(0.1f,1.0f); 849 if (rdm <= m_GoldDropRang)//如果在爆率中则爆金币 850 { 851 GameObject go = Instantiate(m_GoldExp, this.transform.position, this.transform.rotation) as GameObject; 852 go.GetComponent<GoldExp>().m_GoldCount = Random.Range(m_GoldDropCountMin,m_GoldDropCountMax); 853 854 } 855 856 } 857 858 /// <summary> 859 /// 设置金币掉落 860 /// </summary> 861 public void SetGoldFasle() 862 { 863 DropGoldbl = false; 864 } 865 866 867 868 /// <summary> 869 /// 添加某种类型怪物击杀数。 870 /// </summary> 871 public void SenceSetCount() 872 { 873 switch (m_EnemyState) 874 { 875 case EnemyType.EnemyBomb: 876 m_SenceManager.SetCount(GameEndCountType.EnemyBomb); 877 878 break; 879 case EnemyType.EnemyShot: 880 881 m_SenceManager.SetCount(GameEndCountType.EnemyShot); 882 883 break; 884 case EnemyType.EnemyFight: 885 886 m_SenceManager.SetCount(GameEndCountType.EnemyFight); 887 888 break; 889 case EnemyType.EnemyAOE: 890 891 892 m_SenceManager.SetCount(GameEndCountType.EnemyAOE); 893 break; 894 case EnemyType.BossOne: 895 896 897 m_SenceManager.SetCount(GameEndCountType.BossOne); 898 break; 899 case EnemyType.BossTwo: 900 901 m_SenceManager.SetCount(GameEndCountType.BossTwo); 902 903 break; 904 case EnemyType.BossThree: 905 906 907 m_SenceManager.SetCount(GameEndCountType.BossThree); 908 break; 909 case EnemyType.BossFour: 910 911 m_SenceManager.SetCount(GameEndCountType.BossFour); 912 913 break; 914 case EnemyType.BossFive: 915 916 m_SenceManager.SetCount(GameEndCountType.BossFive); 917 918 break; 919 case EnemyType.Null: 920 break; 921 case EnemyType.Enemylair: 922 break; 923 default: 924 break; 925 } 926 } 927 928 int damagecounti = 0; 929 930 private void PlayDeathActionOnce() 931 { 932 if (i <= 0) 933 { 934 MyAnimation.Play("death"); 935 i++; 936 } 937 938 if (MyAnimation["death"].time > MyAnimation["death"].length - 0.1f) 939 { 940 MyAnimation.Stop(); 941 } 942 } 943 944 945 }1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.87.88.89.90.91.92.93.94.95.96.97.98.99.100.101.102.103.104.105.106.107.108.109.110.111.112.113.114.115.116.117.118.119.120.121.122.123.124.125.126.127.128.129.130.131.132.133.134.135.136.137.138.139.140.141.142.143.144.145.146.147.148.149.150.151.152.153.154.155.156.157.158.159.160.161.162.163.164.165.166.167.168.169.170.171.172.173.174.175.176.177.178.179.180.181.182.183.184.185.186.187.188.189.190.191.192.193.194.195.196.197.198.199.200.201.202.203.204.205.206.207.208.209.210.211.212.213.214.215.216.217.218.219.220.221.222.223.224.225.226.227.228.229.230.231.232.233.234.235.236.237.238.239.240.241.242.243.244.245.246.247.248.249.250.251.252.253.254.255.256.257.258.259.260.261.262.263.264.265.266.267.268.269.270.271.272.273.274.275.276.277.278.279.280.281.282.283.284.285.286.287.288.289.290.291.292.293.294.295.296.297.298.299.300.301.302.303.304.305.306.307.308.309.310.311.312.313.314.315.316.317.318.319.320.321.322.323.324.325.326.327.328.329.330.331.332.333.334.335.336.337.338.339.340.341.342.343.344.345.346.347.348.349.350.351.352.353.354.355.356.357.358.359.360.361.362.363.364.365.366.367.368.369.370.371.372.373.374.375.376.377.378.379.380.381.382.383.384.385.386.387.388.389.390.391.392.393.394.395.396.397.398.399.400.401.402.403.404.405.406.407.408.409.410.411.412.413.414.415.416.417.418.419.420.421.422.423.424.425.426.427.428.429.430.431.432.433.434.435.436.437.438.439.440.441.442.443.444.445.446.447.448.449.450.451.452.453.454.455.456.457.458.459.460.461.462.463.464.465.466.467.468.469.470.471.472.473.474.475.476.477.478.479.480.481.482.483.484.485.486.487.488.489.490.491.492.493.494.495.496.497.498.499.500.501.502.503.504.505.506.507.508.509.510.511.512.513.514.515.516.517.518.519.520.521.522.523.524.525.526.527.528.529.530.531.532.533.534.535.536.537.538.539.540.541.542.543.544.545.546.547.548.549.550.551.552.553.554.555.556.557.558.559.560.561.562.563.564.565.566.567.568.569.570.571.572.573.574.575.576.577.578.579.580.581.582.583.584.585.586.587.588.589.590.591.592.593.594.595.596.597.598.599.600.601.602.603.604.605.606.607.608.609.610.611.612.613.614.615.616.617.618.619.620.621.622.623.624.625.626.627.628.629.630.631.632.633.634.635.636.637.638.639.640.641.642.643.644.645.646.647.648.649.650.651.652.653.654.655.656.657.658.659.660.661.662.663.664.665.666.667.668.669.670.671.672.673.674.675.676.677.678.679.680.681.682.683.684.685.686.687.688.689.690.691.692.693.694.695.696.697.698.699.700.701.702.703.704.705.706.707.708.709.710.711.712.713.714.715.716.717.718.719.720.721.722.723.724.725.726.727.728.729.730.731.732.733.734.735.736.737.738.739.740.741.742.743.744.745.746.747.748.749.750.751.752.753.754.755.756.757.758.759.760.761.762.763.764.765.766.767.768.769.770.771.772.773.774.775.776.777.778.779.780.781.782.783.784.785.786.787.788.789.790.791.792.793.794.795.796.797.798.799.800.801.802.803.804.805.806.807.808.809.810.811.812.813.814.815.816.817.818.819.820.821.822.823.824.825.826.827.828.829.830.831.832.833.834.835.836.837.838.839.840.841.842.843.844.845.846.847.848.849.850.851.852.853.854.855.856.857.858.859.860.861.862.863.864.865.866.867.868.869.870.871.872.873.874.875.876.877.878.879.880.881.882.883.884.885.886.887.888.889.890.891.892.893.894.895.896.897.898.899.900.901.902.903.904.905.906.907.908.909.910.911.912.913.914.915.916.917.918.919.920.921.922.923.924.925.926.927.928.929.930.931.932.933.934.935.936.937.938.939.940.941.942.943.944.945.
BOSS属性类
1 using UnityEngine; 2 using System.Collections; 3 4 5 public enum BossType 6 { 7 BossOne1, 8 BossOne2, 9 BossTwo1, 10 BossTwo2, 11 BossThree1, 12 BossThree2, 13 BossThree3 14 15 } 16 17 18 19 public class EnemyBoss :Enemy 20 { 21 private BossAi bossai; 22 private AudioManager m_audiomanager; 23 24 25 void Start() 26 { 27 m_audiomanager = GameObject.FindGameObjectWithTag ("Audio").GetComponent<AudioManager> (); 28 29 AddEnemyBar(); 30 AllStartInit(); 31 bossai = this.GetComponent<BossAi>(); 32 } 33 34 // Update is called once per frame 35 void Update() 36 { 37 if (!m_PlayerControl.isAlive) 38 { 39 return; 40 } 41 42 if (!_isAlive) 43 { 44 MyTransform.position += new Vector3(0, 0.5f, 0); 45 } 46 ChildrenUpdataALL(); 47 Burning(); 48 } 49 50 /// <summary> 51 /// 判断一定时间内是否受到伤害 52 /// </summary> 53 /// <returns></returns> 54 public bool isDamage() 55 { 56 bool bl = false; 57 if (damageTime <= 0) 58 { 59 bl = true; 60 } 61 else 62 { 63 bl = false; 64 } 65 66 return bl; 67 } 68 69 public GameObject HitPoint; 70 public GameObject HitEffect; 71 72 public void SetBoxArray(int[] a) 73 { 74 BoxDropArray = a; 75 } 76 77 78 79 /// <summary> 80 /// 受到伤害 81 /// </summary> 82 /// <param name="damage"></param> 83 public new void EnemyOnDamage(int damage) 84 { 85 //求通过暴击率更改伤害值 86 PlayerControl m_PlayerControl = player.GetComponent<PlayerControl>(); 87 float CritRate = m_PlayerControl.CritRate; 88 float rand = Random.Range(0.01f, 10.0f); 89 90 if (_curHealth > 0)// && isDamage()) 91 { 92 if (!bossai.Rushing) 93 { 94 95 GameObject hplabel = Instantiate(HPlable, Vector3.zero, Quaternion.identity) as GameObject; 96 97 m_audiomanager.Enemy_Hit(); //播放受击声音 98 99 Instantiate(HitEffect, HitPoint.transform.position, HitPoint.transform.rotation); 100 101 if (rand <= CritRate)//暴击 102 { 103 Vector3 vec = new Vector3(3.0f, 3.0f, 3.0f); 104 hplabel.SendMessage("m_SetScale", vec); 105 hplabel.GetComponent<UILabel>().color = Color.yellow; 106 damage *= 2; 107 108 } 109 else 110 { 111 hplabel.GetComponent<UILabel>().color = Color.red; 112 } 113 114 hplabel.SendMessage("SetTarget", this.gameObject); 115 hplabel.SendMessage("SetValue", damage); 116 117 _curHealth -= damage; 118 } 119 damageTime = 0.2f; 120 } 121 122 Debug.Log("enemyondamage"); 123 } 124 125 /// <summary> 126 /// 受到伤害 127 /// </summary> 128 /// <param name="damage"></param> 129 public void EnemyOnDamageFOW(int damage) 130 { 131 if (CurrentDamage <= 0) 132 { 133 EnemyOnDamage(damage); 134 } 135 CurrentDamage++; 136 } 137 138 /// <summary> 139 /// 生命限制事件 140 /// </summary> 141 public void EnemyVital() 142 { 143 144 #region 生命溢出限制 145 if (_curHealth > _maxHealth) 146 { 147 _curHealth = _maxHealth; 148 } 149 150 if (_curHealth <= 0) 151 { 152 _curHealth = 0; 153 _isAlive = false; 154 } 155 156 #endregion 157 158 } 159 160 /// <summary> 161 /// 子类调用的通用事件 162 /// </summary> 163 public void ChildrenUpdataALL() 164 { 165 FOWtime -= Time.deltaTime; 166 if (FOWtime <= 0) 167 { 168 CurrentDamage = 0; 169 FOWtime = 3; 170 } 171 damageTime -= Time.deltaTime; 172 173 DeathEvent(); 174 EnemyVital(); 175 ArmorPiercingCheck(); 176 } 177 178 /// <summary> 179 /// 死亡事件 渐渐下落 然后销毁 180 /// </summary> 181 public new void DeathEvent() 182 { 183 if (!_isAlive) 184 { 185 186 //碰撞器false 187 cc.enabled = false; 188 PlayDeathActionOnce(); 189 this.transform.Translate(0, -0.002f, 0); 190 191 DeadDestoryTime -= Time.deltaTime; 192 193 if (DeadDestoryTime <= 0) 194 { 195 SenceSetCount(); 196 Destroy(this.gameObject); 197 } 198 if (DropCount <= 0)//死亡后设置一次掉落 199 { 200 bossai.RushEffect.SetActive(false); 201 202 //int RandKey = Random.Range(1, 10); 203 204 //if (RandKey <= DropRange)//判断血瓶掉落几率 205 { 206 if (EnemyDrop)//掉落宝箱 207 { 208 StartCoroutine(dropbox()); 209 } 210 } 211 212 if (m_GoldExp) 213 { 214 //DropGold(); 215 } 216 217 DropCount++; 218 } 219 } 220 } 221 222 223 IEnumerator dropbox() 224 { 225 yield return new WaitForSeconds(1.5f); 226 227 Vector3 m_position = new Vector3(transform.position.x, transform.position.y, transform.position.z + 2.5f); 228 229 GameObject go = Instantiate(EnemyDrop, m_position,Quaternion.Euler(0,-135,0) ) as GameObject; 230 231 232 go.GetComponent<BossBox>().SetDurgList(GameManager.GetInstance().BossBoxRandom(BoxDropArray)); 233 234 235 //switch (m_EnemyState) 236 //{ 237 // case EnemyType.EnemyBomb: 238 239 // break; 240 // case EnemyType.EnemyShot: 241 // break; 242 // case EnemyType.EnemyFight: 243 // break; 244 // case EnemyType.EnemyAOE: 245 // break; 246 // case EnemyType.BossOne: 247 // go.GetComponent<BossBox>().SetDurgList(GameManager.GetInstance().BossBoxRandom(GameManager.BossOneArray)); 248 // break; 249 // case EnemyType.BossTwo: 250 // go.GetComponent<BossBox>().SetDurgList(GameManager.GetInstance().BossBoxRandom(GameManager.BossTwoArray)); 251 // break; 252 // case EnemyType.BossThree: 253 // go.GetComponent<BossBox>().SetDurgList(GameManager.GetInstance().BossBoxRandom(GameManager.BossThreeArray)); 254 // break; 255 // case EnemyType.BossFour: 256 // go.GetComponent<BossBox>().SetDurgList(GameManager.GetInstance().BossBoxRandom(GameManager.BossFourArray)); 257 // break; 258 // case EnemyType.BossFive: 259 // go.GetComponent<BossBox>().SetDurgList(GameManager.GetInstance().BossBoxRandom(GameManager.BossFiveArray)); 260 // break; 261 // case EnemyType.Null: 262 // break; 263 // case EnemyType.Enemylair: 264 // break; 265 // default: 266 // break; 267 //} 268 269 } 270 271 272 private void PlayDeathActionOnce() 273 { 274 if (i <= 0) 275 { 276 MyAnimation.Play("daying"); 277 i++; 278 } 279 280 if (MyAnimation["daying"].time > MyAnimation["daying"].length - 0.1f) 281 { 282 MyAnimation.Stop(); 283 } 284 } 285 }1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.87.88.89.90.91.92.93.94.95.96.97.98.99.100.101.102.103.104.105.106.107.108.109.110.111.112.113.114.115.116.117.118.119.120.121.122.123.124.125.126.127.128.129.130.131.132.133.134.135.136.137.138.139.140.141.142.143.144.145.146.147.148.149.150.151.152.153.154.155.156.157.158.159.160.161.162.163.164.165.166.167.168.169.170.171.172.173.174.175.176.177.178.179.180.181.182.183.184.185.186.187.188.189.190.191.192.193.194.195.196.197.198.199.200.201.202.203.204.205.206.207.208.209.210.211.212.213.214.215.216.217.218.219.220.221.222.223.224.225.226.227.228.229.230.231.232.233.234.235.236.237.238.239.240.241.242.243.244.245.246.247.248.249.250.251.252.253.254.255.256.257.258.259.260.261.262.263.264.265.266.267.268.269.270.271.272.273.274.275.276.277.278.279.280.281.282.283.284.285.
BOSS行为代码:
1 using UnityEngine; 2 using System.Collections; 3 4 public enum BossState { 5 idle,//idel 6 walk,//walk 7 run,//run 8 bullet1,//bullet1 9 bullet2,//bullet2 10 attack1,//stabbing 11 attack2,//stright 12 attack3,// 13 Rushing, 14 daying 15 } 16 17 public enum BossAttackState 18 { 19 Step1,//攻击阶段1 :发射弹幕1 两轮 20 Step2,//追逐主角 20秒标记 追上主角就肉搏打击 然后发射弹幕1 两轮 ,循环3次后进入Step3 21 Step3,//发射弹幕2 更改弹幕发射为随机 进入Step1 重置Step2count 22 Null 23 } 24 25 public class BossAi : MonoBehaviour { 26 27 28 public GameObject Bullet1;//弹幕1 29 public GameObject Bullet2;//弹幕2 30 public BossState BossST = BossState.idle; 31 32 public GameObject RushEffect; 33 34 public int Step2count = 0; 35 public bool BulletRandom = false; 36 public float Step2TimerCD = 20; 37 public float Step2Timer = 0; 38 39 public Transform m_GunPoint; 40 41 42 public BossAttackState m_BossAttackState = BossAttackState.Step1; 43 44 private AudioManager m_audioManager; 45 46 void Awake() 47 { 48 m_audioManager = GameObject.FindGameObjectWithTag ("Audio").GetComponent<AudioManager> (); 49 } 50 /// <summary> 51 /// 释放弹幕1 52 /// </summary> 53 public void Bullet1Attack() 54 { 55 56 GameObject go = Instantiate(Bullet1, new Vector3(this.transform.position.x, this.transform.position.y + 1.0f, this.transform.position.z), this.transform.rotation) as GameObject; 57 //go.GetComponent<bulletOne>().Boss = this.gameObject; 58 BossST = BossState.bullet1; 59 } 60 61 /// <summary> 62 /// 释放弹幕1 通过事件添加 63 /// </summary> 64 public void Bullet3Attack() 65 { 66 Debug.Log ("=========枪发子弹==========="); 67 m_audioManager.Boss1_ZiDan (); 68 69 GameObject go = Instantiate(Bullet1, new Vector3(m_GunPoint.position.x, m_GunPoint.position.y, m_GunPoint.position.z), this.transform.rotation) as GameObject; 70 //go.GetComponent<bulletOne>().Boss = this.gameObject; 71 BossST = BossState.bullet1; 72 } 73 74 /// <summary> 75 /// 释放弹幕2 76 /// </summary> 77 public void Bullet2Attack() 78 { 79 Debug.Log ("=========发射火焰==========="); 80 m_audioManager.Boss1_HuoYan (); 81 82 GameObject go = Instantiate(Bullet2, new Vector3(this.transform.position.x,this.transform.position.y,this.transform.position.z),this.transform.rotation) as GameObject; 83 //go.transform.LookAt(player.transform.position); 84 BossST = BossState.bullet2; 85 } 86 87 private float _maxHealth = 1; //最大生命值 88 private float _curHealth = 1; //当前生命值 89 public Enemy enemy; 90 public Transform MyTransform; 91 private bool _isAlive = true; //怪物是否活着 92 private float _moveSpeed; //怪物移动速度 93 private int _rotationSpeed; //怪物旋转速度 94 GameObject player;//玩家 95 public Transform _target;//目标 96 public CharacterController cc; 97 Animation MyAnimation; 98 int bulletonecount = 0;//判断是否发射弹幕1次 99 public NavMeshAgent nma;//用于存储Robot身上附带的NavMeshAgent组件 100 101 public float BulletOneDelay; 102 103 104 105 // Use this for initialization 106 void Start() 107 { 108 109 RushEffect.SetActive(false); 110 enemy = this.GetComponent<Enemy>(); 111 112 if (enemy.m_EnemyState == EnemyType.BossOne) 113 { 114 BulletOneDelay = 6.0f; 115 } 116 else 117 { 118 BulletOneDelay = 3.0f; 119 } 120 121 //从enemy那初始化所有数据 122 _maxHealth = enemy._maxHealth; 123 _curHealth = enemy._curHealth; 124 _isAlive = enemy._isAlive; 125 _moveSpeed = enemy._moveSpeed; 126 _rotationSpeed = enemy._rotationSpeed; 127 128 player = GameObject.FindGameObjectWithTag("Player"); 129 _target = player.transform; 130 cc = this.GetComponent<CharacterController>(); 131 MyTransform = this.transform; 132 MyAnimation = this.animation; 133 134 nma = GetComponent<NavMeshAgent>(); 135 nma.SetDestination(_target.position);//设置目的地位射线与平面的碰撞点 136 137 if (enemy.m_EnemyState == EnemyType.BossOne) 138 { 139 140 AnimationEvent evt = new AnimationEvent(); 141 evt.time = 0.3f; 142 evt.functionName = "Bullet3Attack"; 143 animation.GetClip("bullet1").AddEvent(evt); 144 145 } 146 147 } 148 149 150 public float BulletOneCD = 10.0f;//弹幕1冷却时间 151 private float BulletOneTimer = 0.0f;//弹幕1时间累加器 152 public float BulletTwoCD = 15.0f;//弹幕2冷却时间 153 private float BulletTwoTimer = 0.0f;//弹幕2时间累加器 154 public float RushCD = 8.0f; //野蛮冲撞冷却时间 155 private float RushTimer = 7.0f;//野蛮冲撞时间累加器 156 public float RushAttackDistance = 10.0f;//野蛮冲撞判断距离,在此距离内使用野蛮冲撞 157 public float SkillConflictCD = 5.0f; //不同技能的使用间隔 158 private float SkillConflictTimer = 0.0f; //判断是否能使用技能的时间累加器 159 160 161 162 void OnGUI() 163 { 164 //GUI.Box(new Rect(111, 111, 111, 50), Step2Timer.ToString()+" "+Step2count.ToString()); 165 } 166 167 /// <summary> 168 /// 弹幕一攻击协同 169 /// </summary> 170 /// <returns></returns> 171 IEnumerator StepOneC() 172 { 173 if (enemy.m_EnemyState == EnemyType.BossOne) 174 { 175 ContUsed = true; 176 MustFackToPlayer = true; 177 yield return new WaitForSeconds(0.01f); 178 _moveSpeed = 0; 179 yield return new WaitForSeconds(0.01f); 180 BossST = BossState.bullet1; 181 //Bullet1Attack(); 182 yield return new WaitForSeconds(BulletOneDelay); 183 //Bullet1Attack(); 184 yield return new WaitForSeconds(BulletOneDelay); 185 MustFackToPlayer = true;//冲撞的时候不能面向玩家 186 _moveSpeed = enemy._moveSpeed; 187 BossST = BossState.walk; 188 ContUsed = false; 189 yield break; 190 191 } 192 else 193 { 194 ContUsed = true; 195 MustFackToPlayer = true; 196 yield return new WaitForSeconds(0.01f); 197 _moveSpeed = 0; 198 yield return new WaitForSeconds(0.01f); 199 Bullet1Attack(); 200 yield return new WaitForSeconds(BulletOneDelay); 201 Bullet1Attack(); 202 yield return new WaitForSeconds(BulletOneDelay); 203 MustFackToPlayer = true;//冲撞的时候不能面向玩家 204 _moveSpeed = enemy._moveSpeed; 205 BossST = BossState.walk; 206 ContUsed = false; 207 yield break; 208 209 } 210 211 } 212 213 /// <summary> 214 /// 弹幕一攻击协同 215 /// </summary> 216 /// <returns></returns> 217 IEnumerator StepThreeC() 218 { 219 ContUsed = true; 220 yield return new WaitForSeconds(8.01f); 221 _moveSpeed = 0; 222 Bullet2Attack(); 223 yield return new WaitForSeconds(3.0f); 224 _moveSpeed = enemy._moveSpeed; 225 226 BossST = BossState.walk; 227 m_BossAttackState = BossAttackState.Step2; 228 Step2Timer = 0; 229 ContUsed = false; 230 yield break; 231 } 232 233 /// <summary> 234 /// 弹幕一攻击协同 235 /// </summary> 236 /// <returns></returns> 237 IEnumerator bullteOneAttackC() 238 { 239 if (enemy.m_EnemyState == EnemyType.BossOne) 240 { 241 ContUsed = true; 242 MustFackToPlayer = true; 243 yield return new WaitForSeconds(0.01f); 244 _moveSpeed = 0; 245 yield return new WaitForSeconds(0.01f); 246 BossST = BossState.bullet1; 247 //Bullet1Attack(); 248 yield return new WaitForSeconds(BulletOneDelay); 249 MustFackToPlayer = true;//冲撞的时候不能面向玩家 250 _moveSpeed = enemy._moveSpeed; 251 BossST = BossState.walk; 252 ContUsed = false; 253 yield break; 254 255 } 256 else 257 { 258 259 ContUsed = true; 260 MustFackToPlayer = true; 261 yield return new WaitForSeconds(0.01f); 262 _moveSpeed = 0; 263 yield return new WaitForSeconds(0.01f); 264 Bullet1Attack(); 265 yield return new WaitForSeconds(BulletOneDelay); 266 MustFackToPlayer = true;//冲撞的时候不能面向玩家 267 _moveSpeed = enemy._moveSpeed; 268 BossST = BossState.walk; 269 ContUsed = false; 270 yield break; 271 } 272 273 } 274 275 /// <summary> 276 /// 弹幕一攻击协同 277 /// </summary> 278 /// <returns></returns> 279 IEnumerator bullteOneAttackC1() 280 { 281 if (enemy.m_EnemyState == EnemyType.BossOne) 282 { 283 ContUsed = true; 284 MustFackToPlayer = true; 285 yield return new WaitForSeconds(0.01f); 286 _moveSpeed = 0; 287 yield return new WaitForSeconds(0.01f); 288 BossST = BossState.bullet1; 289 //Bullet1Attack(); 290 yield return new WaitForSeconds(BulletOneDelay); 291 MustFackToPlayer = true;//冲撞的时候不能面向玩家 292 _moveSpeed = enemy._moveSpeed; 293 BossST = BossState.walk; 294 ContUsed = false; 295 yield break; 296 297 } 298 else 299 { 300 301 ContUsed = true; 302 MustFackToPlayer = true; 303 yield return new WaitForSeconds(0.01f); 304 _moveSpeed = 0; 305 yield return new WaitForSeconds(0.01f); 306 Bullet1Attack(); 307 yield return new WaitForSeconds(BulletOneDelay); 308 MustFackToPlayer = true;//冲撞的时候不能面向玩家 309 _moveSpeed = enemy._moveSpeed; 310 BossST = BossState.walk; 311 ContUsed = false; 312 yield break; 313 } 314 } 315 316 /// <summary> 317 /// 弹幕2攻击协同 318 /// </summary> 319 /// <returns></returns> 320 IEnumerator bullteTwoAttackC() 321 { 322 ContUsed = true; 323 _moveSpeed = 0; 324 yield return new WaitForSeconds(0.01f); 325 MustFackToPlayer = false; 326 Bullet2Attack(); 327 yield return new WaitForSeconds(3.0f); 328 MustFackToPlayer = true; 329 _moveSpeed = enemy._moveSpeed; 330 BossST = BossState.walk; 331 ContUsed = false; 332 yield break; 333 334 } 335 336 /// <summary> 337 /// 弹幕一攻击协同 338 /// </summary> 339 /// <returns></returns> 340 IEnumerator bullteTwoAttackC1() 341 { 342 ContUsed = true; 343 MyTransform.LookAt(player.transform.position); 344 _moveSpeed = 0; 345 yield return new WaitForSeconds(0.01f); 346 347 Bullet2Attack(); 348 MustFackToPlayer = false; 349 yield return new WaitForSeconds(3.0f); 350 MustFackToPlayer = true; 351 _moveSpeed = enemy._moveSpeed; 352 BossST = BossState.walk; 353 ContUsed = false; 354 yield break; 355 } 356 357 public float Attack1CD = 5.0f;//肉搏打击冷却时间 358 private float Attack1Timer = 0.0f;//肉搏打击时间累加器 359 360 /// <summary> 361 /// 肉搏打击协同 362 /// </summary> 363 /// <returns></returns> 364 IEnumerator BossAttack1C() 365 { 366 367 368 ContUsed = true; 369 _moveSpeed = 0; 370 Debug.Log("Rush技能事件1"); 371 yield return new WaitForSeconds(0.01f); 372 BossST = BossState.attack1; 373 374 375 yield return new WaitForSeconds(0.51f); 376 377 m_audioManager.Boss1_Fight(); //播放boss1肉搏的声音 378 379 _target.SendMessage("OnDamage", 35); 380 _target.SendMessage("GetHit"); 381 yield return new WaitForSeconds(1.0f); 382 _moveSpeed = enemy._moveSpeed; 383 BossST = BossState.walk; 384 ContUsed = false; 385 yield break; 386 } 387 388 public bool Rushing = false;//是否在野蛮冲撞中 389 private int RushCount = 0; 390 391 private bool ContUsed = false; 392 /// <summary> 393 /// 野蛮冲撞协同 394 /// </summary> 395 /// <returns></returns> 396 IEnumerator RushC() 397 { 398 Debug.Log("=======野蛮冲撞======"); 399 RushEffect.SetActive(true); 400 BossST = BossState.run; 401 ContUsed = true; 402 _moveSpeed = 0;//速度置为0,不让移动 403 nma.Stop(); 404 Debug.Log("Rush技能事件1"); 405 yield return new WaitForSeconds(3.01f); 406 BossST = BossState.run; 407 MustFackToPlayer = false;//冲撞的时候不能面向玩家 408 Rushing = true; 409 yield return new WaitForSeconds(1.5f); 410 RushEffect.SetActive(false); 411 Rushing = false; 412 _moveSpeed = 0;//速度置为0,不让移动 413 BossST = BossState.idle; 414 yield return new WaitForSeconds(1.0f); 415 MustFackToPlayer = true;//接触不能面向玩家 416 _moveSpeed = enemy._moveSpeed;// 417 BossST = BossState.walk; 418 nma.SetDestination(_target.position); 419 RushCount = 0;//置为空 420 ContUsed = false; 421 yield break; 422 423 } 424 425 private bool MustFackToPlayer = true; 426 427 /// <summary> 428 /// 设置目标 429 /// </summary> 430 public void SetTarget(GameObject go) 431 { 432 _target = go.transform; 433 } 434 float DistanceWithPlayer; 435 436 public float SecondMode = 0.5f; 437 438 // Update is called once per frame 439 void Update () { 440 441 PlayerAnimaFromState(); 442 _curHealth = enemy._curHealth; 443 _isAlive = enemy._isAlive; 444 m_EnemyOnChaos = enemy.m_EnemyOnChaos; //更新BOSS状态 445 m_EnemyOnFire = enemy.m_EnemyOnFire; // 446 m_EnemyOnFrozen = enemy.m_EnemyOnFrozen; // 447 nma.speed = _moveSpeed;//将速度与enemy类中速度匹配 448 449 if (_isAlive) //如果BOSS活着 450 { 451 if (m_EnemyOnFrozen)//如果在冰冻状态 452 { 453 nma.speed = 0; 454 455 enemy.FrozenTimer += Time.deltaTime;//冰冻时间累加器 456 if (enemy.FrozenTimer >= enemy.FrozenTimeCD) 457 { 458 enemy.m_EnemyOnFrozen = false; 459 enemy.FrozenTimer = 0; 460 } 461 462 }else 463 { 464 nma.speed = _moveSpeed * (1 - 0.2f * enemy.SlowDownLV); 465 } 466 467 468 if (enemy.m_EnemyOnSlowDown)//减速 469 { 470 enemy.m_SlowDownTimer += Time.deltaTime; 471 if (enemy.m_SlowDownTimer >= enemy.m_SlowDownCD) 472 { 473 enemy.m_EnemyOnSlowDown = false; 474 enemy.m_SlowDownTimer = 0.0f; 475 enemy.SlowDownLV = 0; 476 } 477 } 478 479 480 if (m_EnemyOnChaos)//如果在混乱状态 481 { 482 OnChaos();//进入混乱 483 } 484 else 485 { 486 487 if (!_target) //如果目标为空 则设置目标为玩家 488 { 489 SetTarget(player); 490 } 491 Debug.DrawLine(_target.position, MyTransform.position, Color.red);//画线 492 //BOSS和玩家的距离 493 DistanceWithPlayer = Vector3.Distance(_target.transform.position, transform.position); 494 495 Attack1Timer += Time.deltaTime; //打击累加器 496 BulletOneTimer += Time.deltaTime; //子弹1累加器 497 BulletTwoTimer += Time.deltaTime; //子弹2累加器 498 SkillConflictTimer += Time.deltaTime; //两次弹幕时间间隔累加器 499 500 501 if (_curHealth / _maxHealth >= SecondMode) //(血量>=10%)//血量大于10% 启用远程模式 502 { 503 if (MustFackToPlayer) 504 FaceToTarget(_target.gameObject); //面向主角; 505 506 nma.SetDestination(_target.position);//设置目标点 507 508 switch (m_BossAttackState) 509 { 510 case BossAttackState.Step1: 511 nma.speed = 0.0f; 512 StartCoroutine(StepOneC()); //第一步协同 513 m_BossAttackState = BossAttackState.Step2; 514 Step2count = 0; 515 break; 516 case BossAttackState.Step2: 517 if (Step2count>=3) 518 { 519 m_BossAttackState = BossAttackState.Step3; 520 } 521 Step2Timer += Time.deltaTime; 522 if (Step2Timer <= Step2TimerCD)// 523 { 524 if (DistanceWithPlayer <= 3.5f)//(与玩家的距离小于1) 525 { 526 if (Attack1Timer >= Attack1CD && !ContUsed) 527 { 528 StartCoroutine(BossAttack1C()); 529 Attack1Timer = 0; 530 531 Step2count++; 532 Step2Timer = 0; 533 } 534 535 536 Debug.Log("进行一次肉搏打击,将主角击退;"); 537 } 538 } 539 else 540 { 541 if (BulletRandom) 542 { 543 int i = Random.Range(1, 3); 544 switch (i) 545 { 546 case 1: 547 if (!ContUsed) 548 StartCoroutine(bullteOneAttackC1()); //发射弹幕1;//协同 549 break; 550 case 2: 551 if (!ContUsed) 552 StartCoroutine(bullteTwoAttackC1()); //发射弹幕2;//协同 553 break; 554 default: 555 break; 556 } 557 } 558 else 559 { 560 if (!ContUsed) 561 StartCoroutine(bullteOneAttackC1()); //发射弹幕1;//协同 562 } 563 564 Step2count++; 565 Step2Timer = 0; 566 } 567 568 break; 569 case BossAttackState.Step3: 570 StartCoroutine(StepThreeC()); //发射弹幕2;//协同 571 Step2count = 0; 572 BulletRandom = true; 573 Step2Timer = 0; 574 m_BossAttackState = BossAttackState.Step2; 575 break; 576 case BossAttackState.Null: 577 578 break; 579 default: 580 break; 581 } 582 } 583 else//血量小于10%的时候, //随机使用3种攻击方式; 584 { 585 if (MustFackToPlayer) 586 { 587 FaceToTarget(_target.gameObject); //面向主角; 588 589 if (_moveSpeed != 0) 590 { 591 //nma.SetDestination(_target.position);//设置目的地位射线与平面的碰撞点 592 } 593 else 594 { 595 //nma.Stop(); 596 } 597 598 } 599 if (Rushing)//正在野蛮冲撞中 600 { 601 nma.Stop(); 602 nma.speed = 0; 603 604 Vector3 movement1 = transform.forward * 5.0f * 1.5f; 605 movement1 *= Time.deltaTime; 606 cc.Move(movement1); 607 608 if (DistanceWithPlayer <= 2.5f)//如果撞到玩家则对玩家造成伤害 609 { 610 if (RushCount <= 0) 611 { 612 _target.SendMessage("OnDamage", 35); 613 _target.SendMessage("GetHit"); 614 RushCount++; 615 } 616 } 617 618 SkillConflictTimer = 0.0f; 619 620 } 621 else 622 { 623 nma.SetDestination(_target.position);//设置目的地位射线与平面的碰撞点 624 } 625 626 RushTimer += Time.deltaTime; //累加冷却时间 627 if (DistanceWithPlayer >= 2.5f) //(判断是否与玩家距离大于1) 628 { 629 630 if (RushTimer >= RushCD && SkillConflictTimer >= SkillConflictCD && !ContUsed)//if (野蛮冲撞CD冷却,并且在野蛮冲撞距离内) 631 { 632 StartCoroutine(RushC());// 使用野蛮冲撞,并且僵直5秒;//协同 633 RushTimer = 0; // 重置野蛮冲撞CD; 634 SkillConflictTimer = 0;//重置时间 使肉搏打击不冲突 635 } 636 else 637 { 638 if (SkillConflictTimer >= SkillConflictCD && MustFackToPlayer && (!ContUsed)) //判断是否可以发射弹幕 639 { 640 if (BulletOneTimer >= BulletOneCD) //(弹幕1冷却时间到) 641 { 642 int i = Random.Range(1,3); 643 switch (i) 644 { 645 case 1: 646 647 StartCoroutine(bullteOneAttackC()); //发射弹幕1;//协同 648 this.transform.LookAt(_target); 649 650 break; 651 case 2: 652 StartCoroutine(bullteTwoAttackC()); //发射弹幕2;//协同 653 this.transform.LookAt(_target); 654 655 break; 656 default: 657 break; 658 } 659 BulletOneTimer = 0; //重置弹幕冷却时间; 660 } 661 SkillConflictTimer = 0; //重置可发射弹幕冷却时间 662 } 663 } 664 } 665 else 666 { 667 if (DistanceWithPlayer <= 3.5f)//(与玩家的距离小于1) 668 { 669 int yes=0; 670 if (SkillConflictTimer >= SkillConflictCD) 671 { 672 if (Attack1Timer >= Attack1CD && (!ContUsed)) 673 { 674 StartCoroutine(BossAttack1C()); 675 Attack1Timer = 0; 676 } 677 SkillConflictTimer = 0; 678 } 679 680 681 Debug.Log("进行一次肉搏打击,将主角击退;"); //进行一次肉搏打击,将主角击退;//需要在主角那设置一个后退函数 682 } 683 } 684 } 685 } 686 } 687 else 688 { 689 _moveSpeed = 0.0f; 690 nma.Stop(); 691 } 692 } 693 694 private bool m_EnemyOnChaos = false;//混乱状态 695 private float ChaosTimeCD = 5; 696 private float ChaosTimer = 0; 697 private bool m_EnemyOnFrozen = false;//冰冻状态 698 private bool m_EnemyOnFire = false;//燃烧状态 699 private float ChaosWalkCD = 1.0f; 700 private float ChaosWalkTimer = 1.0f; 701 702 703 /// <summary> 704 /// 判断混乱状态 放到update里面 705 /// </summary> 706 public void OnChaos() 707 { 708 //如果混乱中 709 if (enemy.m_EnemyOnChaos) 710 { 711 ChaosTimer += Time.deltaTime;//开始计时 712 SetChaosWalkPoint();//每2秒更换一次跑的地点 713 if (ChaosTimer >= ChaosTimeCD)//混乱时间到 714 { 715 ChaosTimer = 0;//时间制空 716 ChaosWalkTimer = 0.0f; 717 enemy.m_EnemyOnChaos = false;//将混乱状态置F 718 } 719 } 720 } 721 722 /// <summary> 723 /// 每2秒设置一次混乱状态奔跑点 724 /// </summary> 725 void SetChaosWalkPoint() 726 { 727 ChaosWalkTimer += Time.deltaTime; 728 729 if (ChaosWalkTimer >= ChaosWalkCD) 730 { 731 nma.SetDestination(new Vector3(this.transform.position.x + Random.Range(-3.0f, 3.0f), this.transform.position.y, this.transform.position.z + Random.Range(-3.0f, 3.0f)));//设置目的地 732 ChaosWalkTimer = 0; 733 } 734 } 735 736 /// <summary> 737 /// 面向目标 738 /// </summary> 739 /// <param name="target"></param> 740 public void FaceToTarget(GameObject target) 741 { 742 //朝向玩家 y轴不变 743 MyTransform.rotation = Quaternion.Slerp(MyTransform.rotation, Quaternion.LookRotation(new Vector3(target.transform.position.x, 0, target.transform.position.z) - new Vector3(MyTransform.position.x, 0, MyTransform.position.z)), _rotationSpeed * Time.deltaTime); 744 745 } 746 747 /// <summary> 748 /// 从状态更新动画 749 /// </summary> 750 public void PlayerAnimaFromState() 751 { 752 753 if (_isAlive) 754 { 755 if (_moveSpeed == enemy._moveSpeed) 756 { 757 BossST = BossState.walk; 758 } 759 760 if (Rushing) 761 { 762 BossST = BossState.run; 763 } 764 765 switch (BossST) 766 { 767 case BossState.idle: 768 769 MyAnimation.Play("idel"); 770 771 break; 772 case BossState.Rushing: 773 774 MyAnimation.Play("Rushing"); 775 776 break; 777 case BossState.walk: 778 779 MyAnimation["run"].speed = 1.0f; 780 MyAnimation.Play("run"); 781 782 break; 783 case BossState.run: 784 MyAnimation["run"].speed = 1.8f; 785 MyAnimation.Play("run"); 786 787 break; 788 case BossState.bullet1: 789 790 if (enemy.m_EnemyState == EnemyType.BossOne) 791 { 792 MyAnimation["bullet1"].speed = 0.8f; 793 MyAnimation.Play("bullet1"); 794 if (MyAnimation["bullet1"].time > MyAnimation["bullet1"].length - 0.1f) 795 { 796 //BossST = BossState.walk; 797 } 798 } 799 else 800 { 801 MyAnimation["bullet1"].speed = 0.8f; 802 MyAnimation.Play("bullet1"); 803 if (MyAnimation["bullet1"].time > MyAnimation["bullet1"].length - 0.1f) 804 { 805 //BossST = BossState.walk; 806 } 807 } 808 809 810 break; 811 case BossState.bullet2: 812 813 MyAnimation["bullet2"].speed = 0.5f; 814 MyAnimation.Play("bullet2"); 815 if (MyAnimation["bullet2"].time > MyAnimation["bullet2"].length - 0.1f) 816 { 817 //BossST = BossState.walk; 818 } 819 break; 820 case BossState.attack1: 821 MyAnimation["attack1"].speed = 1.5f; 822 MyAnimation.Play("attack1"); 823 if (MyAnimation["attack1"].time > MyAnimation["attack1"].length - 0.1f) 824 { 825 BossST = BossState.idle; 826 } 827 break; 828 case BossState.attack2: 829 830 MyAnimation.Play("attack1"); 831 if (MyAnimation["attack1"].time > MyAnimation["attack1"].length - 0.1f) 832 { 833 MyAnimation.Stop(); 834 } 835 break; 836 case BossState.attack3: 837 838 MyAnimation.Play("attack1"); 839 840 break; 841 case BossState.daying: 842 843 MyAnimation["daying"].speed = 0.1f; 844 MyAnimation.Play("daying"); 845 if (MyAnimation["daying"].time > MyAnimation["daying"].length - 0.1f) 846 { 847 MyAnimation.Stop(); 848 } 849 break; 850 default: 851 break; 852 } 853 } 854 } 855 856 }1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.87.88.89.90.91.92.93.94.95.96.97.98.99.100.101.102.103.104.105.106.107.108.109.110.111.112.113.114.115.116.117.118.119.120.121.122.123.124.125.126.127.128.129.130.131.132.133.134.135.136.137.138.139.140.141.142.143.144.145.146.147.148.149.150.151.152.153.154.155.156.157.158.159.160.161.162.163.164.165.166.167.168.169.170.171.172.173.174.175.176.177.178.179.180.181.182.183.184.185.186.187.188.189.190.191.192.193.194.195.196.197.198.199.200.201.202.203.204.205.206.207.208.209.210.211.212.213.214.215.216.217.218.219.220.221.222.223.224.225.226.227.228.229.230.231.232.233.234.235.236.237.238.239.240.241.242.243.244.245.246.247.248.249.250.251.252.253.254.255.256.257.258.259.260.261.262.263.264.265.266.267.268.269.270.271.272.273.274.275.276.277.278.279.280.281.282.283.284.285.286.287.288.289.290.291.292.293.294.295.296.297.298.299.300.301.302.303.304.305.306.307.308.309.310.311.312.313.314.315.316.317.318.319.320.321.322.323.324.325.326.327.328.329.330.331.332.333.334.335.336.337.338.339.340.341.342.343.344.345.346.347.348.349.350.351.352.353.354.355.356.357.358.359.360.361.362.363.364.365.366.367.368.369.370.371.372.373.374.375.376.377.378.379.380.381.382.383.384.385.386.387.388.389.390.391.392.393.394.395.396.397.398.399.400.401.402.403.404.405.406.407.408.409.410.411.412.413.414.415.416.417.418.419.420.421.422.423.424.425.426.427.428.429.430.431.432.433.434.435.436.437.438.439.440.441.442.443.444.445.446.447.448.449.450.451.452.453.454.455.456.457.458.459.460.461.462.463.464.465.466.467.468.469.470.471.472.473.474.475.476.477.478.479.480.481.482.483.484.485.486.487.488.489.490.491.492.493.494.495.496.497.498.499.500.501.502.503.504.505.506.507.508.509.510.511.512.513.514.515.516.517.518.519.520.521.522.523.524.525.526.527.528.529.530.531.532.533.534.535.536.537.538.539.540.541.542.543.544.545.546.547.548.549.550.551.552.553.554.555.556.557.558.559.560.561.562.563.564.565.566.567.568.569.570.571.572.573.574.575.576.577.578.579.580.581.582.583.584.585.586.587.588.589.590.591.592.593.594.595.596.597.598.599.600.601.602.603.604.605.606.607.608.609.610.611.612.613.614.615.616.617.618.619.620.621.622.623.624.625.626.627.628.629.630.631.632.633.634.635.636.637.638.639.640.641.642.643.644.645.646.647.648.649.650.651.652.653.654.655.656.657.658.659.660.661.662.663.664.665.666.667.668.669.670.671.672.673.674.675.676.677.678.679.680.681.682.683.684.685.686.687.688.689.690.691.692.693.694.695.696.697.698.699.700.701.702.703.704.705.706.707.708.709.710.711.712.713.714.715.716.717.718.719.720.721.722.723.724.725.726.727.728.729.730.731.732.733.734.735.736.737.738.739.740.741.742.743.744.745.746.747.748.749.750.751.752.753.754.755.756.757.758.759.760.761.762.763.764.765.766.767.768.769.770.771.772.773.774.775.776.777.778.779.780.781.782.783.784.785.786.787.788.789.790.791.792.793.794.795.796.797.798.799.800.801.802.803.804.805.806.807.808.809.810.811.812.813.814.815.816.817.818.819.820.821.822.823.824.825.826.827.828.829.830.831.832.833.834.835.836.837.838.839.840.841.842.843.844.845.846.847.848.849.850.851.852.853.854.855.856.
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
赞 收藏 评论 举报
相关文章