EnemyCreate.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class EnemyCreate : MonoBehaviour {
  6. public GameObject Enemy;
  7. public GameObject Enemy2;
  8. public GameObject Boss;
  9. public float CreateTime;
  10. float timer;
  11. public Text enemytext;
  12. PlayerHealth player;
  13. // Use this for initialization
  14. void Start () {
  15. player = GameObject.Find("Player").GetComponent<PlayerHealth>();
  16. }
  17. // Update is called once per frame
  18. void Update () {
  19. GameObject[] normalenemy = GameObject.FindGameObjectsWithTag("Normal Enemy");
  20. GameObject[] Elite = GameObject.FindGameObjectsWithTag("Elite Enemy");
  21. GameObject[] Boss = GameObject.FindGameObjectsWithTag("Boss");
  22. timer += Time.deltaTime;
  23. if (timer >= CreateTime)
  24. {
  25. if (player.currentHealth <= 0) return;
  26. if(Random.Range(0, 500) < 5 + player.Level && Boss.Length < 1 + player.Level / 10)
  27. BossCreate();
  28. if(Random.Range(0, 100) < 9 + player.Level && Elite.Length < 10 + player.Level)
  29. enem2yCreate();
  30. if(normalenemy.Length < 20 + player.Level)
  31. enemyCreate();
  32. timer = 0;
  33. }
  34. CreateTime = 2 - (float)player.Level / 10 < 0.5f ? 0.5f : 2 - (float)player.Level / 10;
  35. enemytext.text = "Enemy: " + normalenemy.Length + "\nElite: " + Elite.Length + "\nBoss: " + Boss.Length;
  36. }
  37. void enemyCreate()
  38. {
  39. //timer = 0;
  40. Instantiate(Enemy, CreatePostion(Random.Range(0,4)), Quaternion.identity);
  41. }
  42. void enem2yCreate()
  43. {
  44. // timer = 0;
  45. Instantiate(Enemy2, CreatePostion(Random.Range(0, 4)), Quaternion.identity);
  46. }
  47. void BossCreate()
  48. {
  49. //timer = 0;
  50. Instantiate(Boss, CreatePostion(Random.Range(0, 4)), Quaternion.identity);
  51. }
  52. Vector3 CreatePostion(int num)
  53. {
  54. Vector3 pos = Vector3.zero;
  55. switch (num)
  56. {
  57. case 0:
  58. pos= new Vector3(0, 0, -30);
  59. break;
  60. case 1:
  61. pos = new Vector3(-30, 0, 0);
  62. break;
  63. case 2:
  64. pos = new Vector3(-5, 0, 24.5f);
  65. break;
  66. case 3:
  67. pos = new Vector3(30, 0, 0);
  68. break;
  69. default:
  70. break;
  71. }
  72. return pos;
  73. }
  74. }