Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.AI;
- [RequireComponent(typeof(NavMeshAgent))]
- public class TankyEnemy : BaseEnemies
- {
- //public GameObject x;
- //public GameObject y;
- private float lastCreation;
- private float allowedCreation = 5.0f;
- public float tankyLifes = 20.0f;
- private float tankyVelocity = 25.0f;
- private int creations = 0;
- public GameObject creation;
- public GameObject spawnPoint;
- private float lastHeal;
- private float allowedHeal = 2.5f;
- private float healValue = 0.1f;
- NavMeshAgent agent;
- private float lastImpactRecived;
- private float startHealing = 2.0f;
- private bool tanky = true;
- private GameObject movDetector;
- // Use this for initialization
- void Start ()
- {
- agent = GetComponent<NavMeshAgent>();
- movDetector = gameObject.transform.Find("Detector").gameObject;
- }
- // Update is called once per frame
- void FixedUpdate()
- {
- Destroyed();
- if (enemyFixed == false)
- {
- Chasing();
- Generating();
- Healing();
- }
- if (enemyFixed == true)
- {
- ChasingFIXED();
- Generating();
- Healing();
- }
- }
- void Chasing()
- {
- if (movDetector.GetComponent<TankyDetector>().onTankyRange == true)
- {
- agent.SetDestination(GameObject.FindGameObjectWithTag("Player").transform.position);
- }
- if (movDetector.GetComponent<TankyDetector>().onTankyRangeENEMY == true)
- {
- agent.destination = movDetector.GetComponent<TankyDetector>().targetedEnemy.transform.position;
- }
- }
- void ChasingFIXED()
- {
- if (movDetector.GetComponent<TankyDetector>().onTankyRangeFIXED == true)
- {
- agent.destination = movDetector.GetComponent<TankyDetector>().targetedEnemy.transform.position;
- }
- }
- void Generating()
- {
- if (movDetector.GetComponent<TankyDetector>().onTankyRange == true && Time.time - lastCreation > allowedCreation)
- {
- if (creations < 2)
- {
- GameObject creationInstance;
- creationInstance = Instantiate(creation, spawnPoint.transform.position, spawnPoint.transform.rotation) as GameObject;
- Rigidbody rigidbodyCreation = creationInstance.GetComponent<Rigidbody>();
- if (enemyFixed == true)
- {
- creationInstance.GetComponent<CreationScript>().parentFixed = true;
- }
- //rigidbodyCreation.AddRelativeForce(Vector3.forward * creationImpulse, ForceMode.Impulse);
- creations++;
- }
- if (creations == 2)
- {
- lastCreation = Time.time;
- creations = 0;
- }
- }
- }
- void Healing()
- {
- if (Time.time > lastImpactRecived + startHealing)
- {
- if (Time.time > lastHeal + allowedHeal)
- {
- tankyLifes += healValue;
- lastHeal = Time.time;
- }
- }
- }
- void OnTriggerEnter(Collider shot)
- {
- if (shot.gameObject.CompareTag("Bullet"))
- {
- tankyLifes--;
- Destroy(shot.gameObject); ;
- lastImpactRecived = Time.time;
- }
- if (shot.gameObject.CompareTag("TurretBullet"))
- {
- tankyLifes -= turretDamage;
- Destroy(shot.gameObject);
- lastImpactRecived = Time.time;
- }
- if (shot.gameObject.CompareTag("Fixing") && knockedOut == true)
- {
- enemyFixed = true;
- tankyLifes = 1.0f;
- }
- }
- void Destroyed()
- {
- if (tankyLifes <= 0 && knockedOut == false)
- {
- // knockedOut = true;
- // knockedOutTime = Time.time;
- //}
- //if (knockedOut == true)
- //{
- // if (Time.time > knockedOutTime + knockedOutWait && enemyFixed == false)
- // {
- // Destroy(gameObject);
- // }
- // Destroy(gameObject);
- Destroy(gameObject);
- }
- }
- }
Add Comment
Please, Sign In to add comment