public connectedPatrolPoint nextWaypoint(connectedPatrolPoint prevPoint) { if (connections.Count <= 0) { Debug.LogError("Not enough connections for a patrol. Triggered by " + gameObject.name); return(null); } else if (connections.Count == 1 && connections.Contains(prevPoint)) { return(prevPoint); } else { connectedPatrolPoint nextWaypoint; int index = 0; do { index = Random.Range(0, connections.Count); nextWaypoint = connections[index]; } while (nextWaypoint == prevPoint); return(nextWaypoint); } }
//Set a destination based on the current patrol index within the patrol points array. public void setDestination() { if (pointsVisited > 0) //if the points visited are greater than one { connectedPatrolPoint nextPoint = curPoint.nextWaypoint(prevPoint); //Get an adjacent waypoint to be the next point prevPoint = curPoint; //Set the prev point curPoint = nextPoint; //Set the current point } UpdatePath(curPoint.gameObject.transform); pointsVisited++; }
public string waypointTag; //This is used to prevent points from getting points in other scenes public void Start() { GameObject[] allWaypoints = GameObject.FindGameObjectsWithTag(waypointTag); connections = new List <connectedPatrolPoint>(); for (int i = 0; i < allWaypoints.Length; i++) { connectedPatrolPoint nextPatrolPoint = allWaypoints[i].GetComponent <connectedPatrolPoint>(); if (nextPatrolPoint != null) { if (Vector3.Distance(gameObject.transform.position, nextPatrolPoint.transform.position) <= connectivityRadius && nextPatrolPoint != this) { connections.Add(nextPatrolPoint); } } } }
public bool hit(GameObject target) { SanityManager targSAN = target.GetComponent <SanityManager>(); clockCntrl clock = target.GetComponent <clockCntrl>(); float dist = Vector2.Distance(target.transform.position, this.gameObject.transform.position); if (clock != null && targSAN != null && dist <= 0.4 && hitTmr == 0) { TimePasserCanv.SetActive(true); timePasser.prepareAnimation(); manager.StopAll(); targSAN.ChangeSanity(-10); clock.adjustTime(120); hitTmr = 200; InvManager.closeCurrInv(); InvCanv.SetActive(false); //Script to fade to black and transfer rooms to cover time change //Trigger animation / fade to black, on timer //timer is inherent to the screen for now, as it's a temporary placeholder feature //Whilst the screen is covered, the BC should be dealt with so that they are not in the same room when the player awakes BCAnimationCanvas.SetActive(true); this.gameObject.transform.position = BCTPPoint.gameObject.transform.position; myRoom = BCTPPoint.myRoom; curPoint = myRoom.getEntrancePoint(); target.transform.position = playerTPPoint.transform.position; target.GetComponent <PlayerMovement>().changeRoom(playerTPPoint.myRoom); target.GetComponent <PlayerMovement>().playerFloor = "FirstFloor"; //Send Typewriter Message SendMessageInOrder(); return(true); } else { Debug.Log("Tried to hit, failed"); return(false); } }