MakeEnemyManager.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class MakeEnemyManager : MonoBehaviour
  5. {
  6. // Start is called before the first frame update
  7. public bool isMakeEnemy = true;
  8. public int myRandomEnemy;//随机生成敌人
  9. public static int myRandomEnemyAllNum;//随机生成多少个敌人
  10. private float myEnemeyPosX;
  11. private float myEnemeyPosZ;
  12. private GameObject enemyPrefab;
  13. public List<GameObject> enemyList = new List<GameObject>();
  14. public bool IsInstantiateEnemy=false;//是否产生敌人
  15. void Start()
  16. {
  17. myRandomEnemyAllNum = 3;
  18. enemyPrefab = Resources.Load("PlayerTypeOfWork") as GameObject;
  19. if (isMakeEnemy)
  20. {
  21. MakeEnemyPrefab(myRandomEnemyAllNum);
  22. }
  23. }
  24. // Update is called once per frame
  25. bool isAddMaxX ;
  26. bool isAddMaxZ ;
  27. int random;
  28. private void LateUpdate()
  29. {
  30. // RoBotEnemyRandomPos();
  31. }
  32. private void MakeEnemyPrefab(int num)
  33. {
  34. {
  35. }
  36. for (int i = 0; i < num; i++)
  37. {
  38. myRandomEnemy = UnityEngine.Random.Range(1, 4);
  39. myEnemeyPosX = UnityEngine.Random.Range(-1000, 1000);
  40. myEnemeyPosZ = UnityEngine.Random.Range(-1000, 1000);
  41. GameObject enemy = Instantiate(enemyPrefab, new Vector3(myEnemeyPosX, 0, myEnemeyPosZ), Quaternion.identity);
  42. enemy.GetComponent<MiniMapFit>().action = "";
  43. enemy.GetComponent<MiniMapFit>().id = i.ToString();
  44. enemy.GetComponent<MiniMapFit>().des = "Enemy" + i.ToString();
  45. enemy.GetComponent<MiniMapFit>().pos = myEnemeyPosX + "_" + "0" + "_" + myEnemeyPosZ;
  46. enemy.GetComponent<MiniMapFit>().eul = "";
  47. if (myRandomEnemy == 1)
  48. {
  49. enemy.GetComponent<MiniMapFit>().typeOfWork = "EnemyTypeOfWork1";
  50. }
  51. else if (myRandomEnemy == 2)
  52. {
  53. enemy.GetComponent<MiniMapFit>().typeOfWork = "EnemyTypeOfWork2";
  54. }
  55. else if (myRandomEnemy == 3)
  56. {
  57. enemy.GetComponent<MiniMapFit>().typeOfWork = "EnemyTanke";
  58. }
  59. enemy.GetComponent<MiniMapFit>().isRobotEnemy = true;
  60. enemyList.Add(enemy);
  61. }
  62. if (IsInstantiateEnemy==false)
  63. {
  64. IsInstantiateEnemy = true;
  65. }
  66. }
  67. public static Vector3 StrSubstringToV3(string str)
  68. {
  69. if (str == null)
  70. {
  71. return new Vector3();
  72. }
  73. string[] s = str.Split('_');
  74. return new Vector3(float.Parse(s[0]), float.Parse(s[1]), float.Parse(s[2]));
  75. }
  76. }