private bool navigateNavMesh(Vector3 position, int roomTo) { roomTargetId = roomTo; ScrFloor target = null; //find a floor gameobject with fitting floor tag //Debug.Log("room TO: " + roomTo); foreach (ScrFloor floor in building.GetComponentsInChildren <ScrFloor>()) { //Debug.Log("room TO: " + floor.roomID); if (floor.roomID == roomTo) { target = floor; Debug.Log("target IS: " + floor); break; } } if (target == null) { return(false); } else { path = new NavMeshPath(); NavMeshAgent agent = user.GetComponent <NavMeshAgent>(); agent.enabled = true; agent.CalculatePath(target.gameObject.transform.position, path); agent.enabled = false; if (path.status == NavMeshPathStatus.PathComplete) { visualizerActivate(path.corners); gameObject.GetComponent <MenuController>().Compass.GetComponent <CompassController>().setTarget(path.corners[0]); gameObject.GetComponent <RouteProgressController>().setRoute(path.corners); PathAutoplay autoplay = user.GetComponent <PathAutoplay>(); if (autoplay != null) { if (autoplay.enabled) { autoplay.activate(path); } } return(true); } else { visualizer.GetComponent <LineRenderer>().SetPositions(null); return(false); } } }
public static ScrFloor FindFloor(Vector3 posFrom) { RaycastHit hit; int layerMask = 1 << 9; if (Physics.Raycast(posFrom, Vector3.down, out hit, 2.8f, layerMask, QueryTriggerInteraction.Collide)) { GameObject gHit = hit.collider.gameObject; ScrFloor floor = gHit.GetComponent <ScrFloor>(); return(floor); } return(null); }
public void floorIDsgenerate() { GameObject floors = GameObject.Find("Floors"); int floorsAmount = floors.transform.childCount; floorsRoomIds = new int[floorsAmount]; for (int n = 0; n < floorsAmount; n++) { ScrFloor f = floors.transform.GetChild(n).gameObject.GetComponent <ScrFloor>(); if (f != null) { f.floorID = n; f.building = this; floorsRoomIds[n] = f.roomID; } } }
int findRoom(Vector3 posFrom) { RaycastHit hit; int layerMask = 1 << 9; if (Physics.Raycast(posFrom, Vector3.down, out hit, 5, layerMask, QueryTriggerInteraction.Collide)) { GameObject gHit = hit.collider.gameObject; ScrFloor floor = gHit.GetComponent <ScrFloor>(); rooms r = building.GetComponent <rooms>(); Debug.Log(r.ToString()); Debug.Log(floor.ToString()); Debug.Log("Object is in Room: " + r.roomNames[floor.roomID]); return(floor.roomID); } return(-1); }
// Update is called once per frame void Update() { if (roomTargetId >= 0) { ScrFloor floor = FindFloor(user.transform.position); if (floor != null) { if (floor.roomID == roomTargetId) { //destination reached GetComponent <MenuController>().destinationReachedMessageShow(building.GetComponent <rooms>().roomNames[roomTargetId]); GetComponent <MenuController>().resetNavigation(); roomTargetId = -1; } } } }