// Update is called once per frame void Update() { RaycastHit hit; Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition); int groundLayerMask = 1 << 8; //Cycles characters if (gameMode == "paused") { if (Input.GetKeyDown(KeyCode.Backspace) && selectedChar != null && selectedChar.path.entryCount.Count >= 1) { selectedChar.path.UndoPath(); } if (Input.GetKeyDown(KeyCode.Tab)) { CycleCharacters(); } if (Input.GetKeyDown(KeyCode.Delete) && selectedWaypoint != null) { //This doesnt really work. Not entirely sure why. Also need to check that the new path doesnt go through walls before deleting. selectedChar.path.waypoints.Remove(selectedWaypoint); selectedChar.path.CreatePathMesh(); selectedWaypoint = null; } if (Input.GetMouseButtonDown(0)) { if (Physics.Raycast(ray, out hit, Mathf.Infinity, groundLayerMask)) { //First priority: Waypoints if (selectedChar != null && selectedChar.path.waypoints.Count > 0 && FindClosestWaypoint(hit.point) != null) { //This selects a waypoint, the selection is done in the function run in the if statement if (selectedWaypoint != selectedChar.path.waypoints[0]) { gameMode = "drag"; } } //Second priority paths else if (hit.collider.tag == "path") { PathClick(hit); } else { Character temp = FindClosestCharacter(hit.point); if (temp == null) { SetCharWaypoint(hit.point); } else { //Last priority characters SelectCharacter(hit.point); } } } } int charLayerMask = 1 << 10; if (Input.GetMouseButtonDown(1) && selectedChar != null) { if (Physics.Raycast(ray, out hit, Mathf.Infinity, groundLayerMask) && FindClosestWaypoint(hit.point) != null) { gameMode = "aim"; } } if (Input.GetButtonDown("Jump")) { StartTurn(); } //Crap buttons, these should have GUI buttons if (Input.GetKeyDown(KeyCode.Keypad1) && selectedWaypoint != null) { Debug.Log("run!"); Instruction newInstruction = new Instruction(); newInstruction.run = true; selectedWaypoint.wpInstructions.Add(newInstruction); //selectedWaypoint.run = true; } if (Input.GetKeyDown(KeyCode.X) && selectedChar != null) { foreach (Waypoint wp in selectedChar.path.waypoints) { Debug.Log(wp.position); } } } //Game modes if (gameMode == "active") { turnTimer += Time.deltaTime; UpdateCharacters(); if (charsToBeKilled.Count > 0) { EmptyKillList(); } if (turnTimer >= turnLength) { EndTurn(); } } if (gameMode == "aim" && selectedWaypoint != null) { if (Input.GetMouseButton(1)) { if (Physics.Raycast(ray, out hit, Mathf.Infinity, groundLayerMask)) { Debug.DrawRay(selectedWaypoint.position, (GetMousePosition() - selectedWaypoint.position).normalized, Color.red); //selectedWaypoint.AdjustAim(hit.point); } } if (Input.GetMouseButtonUp(1)) { Instruction newInstruction = new Instruction(); newInstruction.AdjustAim(GetMousePosition(), selectedWaypoint.position); selectedWaypoint.wpInstructions.Add(newInstruction); gameMode = "paused"; } } if (gameMode == "drag") { if (Input.GetMouseButton(0) && selectedWaypoint != null) { Vector3 mousePos = GetMousePosition(); if (Vector3.Distance(mousePos, selectedWaypoint.position) < 1.0f) { if (ghostPoint == null) { ghostPoint = new Waypoint(selectedWaypoint.position); } selectedWaypoint.position = mousePos; selectedWaypoint.wpMesh.transform.position = selectedWaypoint.position; pathAltered = true; } } if (Input.GetMouseButtonUp(0)) { if (pathAltered) { if (selectedChar.path.CheckWaypointReachable(selectedWaypoint)) { selectedChar.path.CreatePathMesh(); selectedWaypoint.wpMesh.transform.position = selectedWaypoint.position; pathAltered = false; } else { Debug.Log("bam!"); selectedWaypoint.position = ghostPoint.position; selectedWaypoint.wpMesh.transform.position = ghostPoint.position; } ghostPoint = null; } gameMode = "paused"; } } }