void Start() { speed = PlayerPrefs.GetFloat("DroneSpeed", speed); ID = CentralProcessingData.GenerateID(); CentralProcessingData.RequestPath(transform.position, target, ID, OnPathFound); lineRenderer.startColor = new Color(UnityEngine.Random.Range(0.0f, 1), 0, UnityEngine.Random.Range(0.0f, 1)); lineRenderer.endColor = lineRenderer.startColor; }
void Awake() { instance = this; totalDroneCount = 0; droneID = new List <int>(); targets = new List <Vector3>(); pathfinder = pathFinderGO.GetComponent <PathFinding>(); GameObject[] targetsGO = GameObject.FindGameObjectsWithTag("Target"); for (int i = 0; i < targetsGO.Length; i++) { targets.Add(targetsGO[i].transform.position); } }
IEnumerator CreateDrone() { yield return(new WaitForSeconds(UnityEngine.Random.Range(1.0f, 5.0f))); while (true) { if (_d == null && CentralProcessingData.IsNodeClear(transform.position)) { _d = Instantiate(drone, transform.position, transform.rotation); _d.GetComponent <Drone_V1>().target = CentralProcessingData.GetRandomTarget(); } yield return(new WaitForSeconds(UnityEngine.Random.Range(genTime.x, genTime.y))); } }
void OnPathFound(Vector3[] newPath, Boolean pathSuccessfull) { if (pathSuccessfull) { path = newPath; CentralProcessingData.RegisterDrone(); lineRenderer.positionCount = path.Length + 1; lineRenderer.SetPosition(0, transform.position); for (int i = 0; i < path.Length; i++) { lineRenderer.SetPosition(i + 1, path[i]); } StopCoroutine("FollowPath"); StartCoroutine("FollowPath"); } else { DestroyImmediate(gameObject); } }
IEnumerator FollowPath() { Vector3 currentWaypoint = path[0]; while (true) { if (transform.position == currentWaypoint) { targetIndex++; if (targetIndex >= path.Length) { break; } currentWaypoint = path[targetIndex]; } transform.position = Vector3.MoveTowards(transform.position, currentWaypoint, speed * Time.deltaTime); transform.rotation = Quaternion.LookRotation(currentWaypoint - transform.position); yield return(new WaitForEndOfFrame()); } CentralProcessingData.ClearPath(ID); yield return(null); Destroy(gameObject, 1.0f); }
void Awake() { grid = GetComponent <GridClass>(); CPD = CPD_GameObject.GetComponent <CentralProcessingData>(); routes = new Dictionary <int, List <Node> >(); }