void Start() { GameObject[] templightarray = new GameObject[1]; templightarray = GameObject.FindGameObjectsWithTag("Flashlight"); // grabs a copy of every flashlight in the scene Light2D templightobject; flashlightObject = new GameObject[3]; flashlightLight2D = new Light2D[3]; int j = 0; for (int i = 0; i < templightarray.Length; ++i) { if (Vector2.Distance(transform.position, templightarray[i].transform.position) < 1f) { templightobject = templightarray[i].GetComponent <Light2D>(); if (templightobject.pointLightOuterRadius == 7.5f) // change the float to be the outter radius of the lowest alert level flashlight { flashlightObject[0] = templightarray[i]; flashlightLight2D[0] = templightobject; } else if (templightobject.pointLightOuterRadius == 8.5f) // change the float to be the outter radius of the medium alert level flashlight { flashlightObject[1] = templightarray[i]; flashlightLight2D[1] = templightobject; } else if (templightobject.pointLightOuterRadius == 10f) // change the float to be the outter radius of the highest alert level flashlight { flashlightObject[2] = templightarray[i]; flashlightLight2D[2] = templightobject; } } } flashlightObject[1].SetActive(false); // disables the two higher alert flashlights flashlightObject[2].SetActive(false); waitTime = startWaitTime; pathfindingIndex = 0; isPathfinding = false; isSearching = false; actualPlayer = GameObject.FindGameObjectWithTag("Player"); closestWaypoint = gameObject.GetComponent <ClosestWaypoint>(); wscopy = closestWaypoint.GetComponent <WaypointScript>(); patrolRoute = new Transform[routeWaypoints.Length]; index = 0; foreach (GameObject node in routeWaypoints) { patrolRoute[index] = node.transform; index++; } waitTime = startWaitTime; }
private void Update() { wscopy = closestWaypoint.GetComponent <WaypointScript>(); if (isPathfinding && !isSearching) { FollowNodePath(); } else if (inView == true) { isChasing = true; Chase(); } else if (inView == false && isChasing == true && isPathfinding == false) { isSearching = true; } else { Patrol(); } }