Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class DroneManager : MonoBehaviour
- {
- public GameObject dronePrefab;
- public GameObject atkTarget;
- Vector3 targetCurrentPos;
- public int maxDrones;
- DroneManager droneManage;
- DroneMove droneMove;
- DroneHealth droneHealth;
- DroneAtk droneAtk;
- public string droneOwner;
- public string droneTag;
- public int droneLayer;
- ShipHealth ship_HP;
- public List<GameObject> drones = new List<GameObject>();
- public int droneCount;
- int droneID;
- public float droneRange; //how far can the carrier release it's drones
- public float distFromEnemy; //distance between player and Enemy Target.
- public GameObject selectedTarget;
- GameObject tempHolder;
- public GameObject thisObj;
- float droneSpawn_Delay;
- protected float distanceFromTgt;
- protected bool generateRndPoints;
- // Start is called before the first frame update
- void Start()
- {
- //targetCurrentPos = atkTarget.position;
- thisObj = this.gameObject;
- ship_HP = GetComponent<ShipHealth>();
- generateRndPoints = true;
- //InvokeRepeating("RndPointCheck", 0.0f, 0.3f);
- }
- // Update is called once per frame
- void LateUpdate()
- {
- TargetDestroyed();
- if (atkTarget != null)
- {
- UpdateTargetPos();
- }
- if (selectedTarget != null)
- {
- CheckEnemyDist();
- }
- if (ship_HP.isDead == true)
- {
- foreach (GameObject drone in drones)
- {
- drones.Remove(drone);
- Destroy(drone);
- }
- }
- }
- public void RndPointCheck()
- {
- if (generateRndPoints == true)
- {
- generateRndPoints = false;
- //Debug.Log("Generate Points:" + generateRndPoints);
- }
- else if (generateRndPoints == false)
- {
- generateRndPoints = true;
- //Debug.Log("Generate Points:" + generateRndPoints);
- }
- }
- public void CheckEnemyDist()
- {
- distFromEnemy = Vector3.Distance(thisObj.transform.position, selectedTarget.transform.position);
- }
- public void DeleteInterceptors(GameObject dronetbd)
- {
- drones.Remove(dronetbd);
- }
- void TargetDestroyed()
- {
- if (selectedTarget == null)
- {
- if (drones.Count > 0)
- {
- RecallInterceptors();
- }
- }
- }
- public void UpdateTarget(Transform newTarget)
- {
- foreach (GameObject drone in drones)
- {
- droneMove = drone.GetComponent<DroneMove>();
- droneMove.target = newTarget;
- droneMove.newTarget = true;
- }
- targetCurrentPos = atkTarget.transform.position;
- }
- public void UpdateTargetPos()
- {
- if (atkTarget.transform.position != targetCurrentPos)
- {
- foreach (GameObject drone in drones)
- {
- droneMove = drone.GetComponent<DroneMove>();
- droneMove.GenerateRndPoints();
- }
- targetCurrentPos = atkTarget.transform.position;
- }
- }
- public void SpawnInterceptors()
- {
- while (drones.Count < maxDrones)
- {
- tempHolder = Instantiate(dronePrefab, this.transform.position, this.transform.rotation);
- tempHolder.gameObject.tag = droneOwner;
- tempHolder.layer = droneLayer;
- drones.Add(tempHolder);
- droneMove = tempHolder.GetComponent<DroneMove>();
- droneMove.target = atkTarget.transform;
- droneMove.carrier = thisObj;
- droneMove.obj_Tag = droneOwner;
- droneHealth = tempHolder.GetComponent<DroneHealth>();
- droneHealth.droneManage = thisObj.GetComponent<DroneManager>();
- droneAtk = tempHolder.GetComponent<DroneAtk>();
- droneAtk.targetedObj = atkTarget;
- droneAtk.droneManager = thisObj.GetComponent<DroneManager>();
- droneAtk.atkTag = atkTarget.tag;
- }
- }
- public void RecallInterceptors()
- {
- foreach (GameObject drone in drones)
- {
- droneMove = drone.GetComponent<DroneMove>();
- droneMove.target = null;
- }
- }
- }
Add Comment
Please, Sign In to add comment