Guest User

Untitled

a guest
Jun 25th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.AI;
  5.  
  6. [RequireComponent(typeof(NavMeshAgent))]
  7.  
  8. public class TankyEnemy : BaseEnemies
  9. {
  10. //public GameObject x;
  11. //public GameObject y;
  12.  
  13. private float lastCreation;
  14. private float allowedCreation = 5.0f;
  15. public float tankyLifes = 20.0f;
  16. private float tankyVelocity = 25.0f;
  17. private int creations = 0;
  18. public GameObject creation;
  19. public GameObject spawnPoint;
  20. private float lastHeal;
  21. private float allowedHeal = 2.5f;
  22. private float healValue = 0.1f;
  23. NavMeshAgent agent;
  24. private float lastImpactRecived;
  25. private float startHealing = 2.0f;
  26. private bool tanky = true;
  27.  
  28. private GameObject movDetector;
  29.  
  30. // Use this for initialization
  31. void Start ()
  32. {
  33. agent = GetComponent<NavMeshAgent>();
  34. movDetector = gameObject.transform.Find("Detector").gameObject;
  35. }
  36.  
  37. // Update is called once per frame
  38. void FixedUpdate()
  39. {
  40. Destroyed();
  41. if (enemyFixed == false)
  42. {
  43. Chasing();
  44. Generating();
  45. Healing();
  46. }
  47. if (enemyFixed == true)
  48. {
  49. ChasingFIXED();
  50. Generating();
  51. Healing();
  52. }
  53. }
  54. void Chasing()
  55. {
  56. if (movDetector.GetComponent<TankyDetector>().onTankyRange == true)
  57. {
  58. agent.SetDestination(GameObject.FindGameObjectWithTag("Player").transform.position);
  59. }
  60. if (movDetector.GetComponent<TankyDetector>().onTankyRangeENEMY == true)
  61. {
  62. agent.destination = movDetector.GetComponent<TankyDetector>().targetedEnemy.transform.position;
  63. }
  64. }
  65. void ChasingFIXED()
  66. {
  67. if (movDetector.GetComponent<TankyDetector>().onTankyRangeFIXED == true)
  68. {
  69. agent.destination = movDetector.GetComponent<TankyDetector>().targetedEnemy.transform.position;
  70. }
  71. }
  72. void Generating()
  73. {
  74. if (movDetector.GetComponent<TankyDetector>().onTankyRange == true && Time.time - lastCreation > allowedCreation)
  75. {
  76. if (creations < 2)
  77. {
  78. GameObject creationInstance;
  79. creationInstance = Instantiate(creation, spawnPoint.transform.position, spawnPoint.transform.rotation) as GameObject;
  80. Rigidbody rigidbodyCreation = creationInstance.GetComponent<Rigidbody>();
  81. if (enemyFixed == true)
  82. {
  83. creationInstance.GetComponent<CreationScript>().parentFixed = true;
  84. }
  85. //rigidbodyCreation.AddRelativeForce(Vector3.forward * creationImpulse, ForceMode.Impulse);
  86. creations++;
  87. }
  88. if (creations == 2)
  89. {
  90. lastCreation = Time.time;
  91. creations = 0;
  92. }
  93. }
  94. }
  95. void Healing()
  96. {
  97. if (Time.time > lastImpactRecived + startHealing)
  98. {
  99. if (Time.time > lastHeal + allowedHeal)
  100. {
  101. tankyLifes += healValue;
  102. lastHeal = Time.time;
  103. }
  104. }
  105. }
  106. void OnTriggerEnter(Collider shot)
  107. {
  108. if (shot.gameObject.CompareTag("Bullet"))
  109. {
  110. tankyLifes--;
  111. Destroy(shot.gameObject); ;
  112. lastImpactRecived = Time.time;
  113. }
  114.  
  115. if (shot.gameObject.CompareTag("TurretBullet"))
  116. {
  117. tankyLifes -= turretDamage;
  118. Destroy(shot.gameObject);
  119. lastImpactRecived = Time.time;
  120. }
  121.  
  122. if (shot.gameObject.CompareTag("Fixing") && knockedOut == true)
  123. {
  124. enemyFixed = true;
  125. tankyLifes = 1.0f;
  126. }
  127. }
  128. void Destroyed()
  129. {
  130. if (tankyLifes <= 0 && knockedOut == false)
  131. {
  132. // knockedOut = true;
  133. // knockedOutTime = Time.time;
  134. //}
  135. //if (knockedOut == true)
  136. //{
  137. // if (Time.time > knockedOutTime + knockedOutWait && enemyFixed == false)
  138. // {
  139. // Destroy(gameObject);
  140. // }
  141. // Destroy(gameObject);
  142. Destroy(gameObject);
  143. }
  144. }
  145.  
  146. }
Add Comment
Please, Sign In to add comment