private void Update() { if (Input.GetMouseButtonDown(0)) { Debug.Log("Mouse Clicked"); Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.CompareTag(targetsTag)) { cam.SetTarget(hit.transform); Debug.Log("You clicked a blob"); } else { Debug.Log("Targeting Mesh"); //NavMeshHit nHit; //Ray ray1 = Camera.main.ScreenPointToRay(Input.mousePosition); //bool hasHit = NavMesh.Raycast(this.transform.position, hit.point, out nHit, NavMesh.AllAreas); Debug.Log("Mesh Targeted"); Debug.Log(hit.point); //randomDestination(10); //Debug.Log("Area ID: " + nHit.mask); //targetPosition = hit.point; //agent.destination = targetPosition; cam.ResetTarget(); } } } if (Input.GetKeyDown(KeyCode.Space)) { TargetingPlayer = !TargetingPlayer; TargetPlayer = PlayerCanvas.canvas.PlayerObject; if (!TargetingPlayer) { cam.SetTarget(TargetPlayer.transform); } else if (TargetingPlayer) { cam.ResetTarget(); } } }
private void Update() { if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) { cam.ResetTarget(); float timeDelta = Time.time - lastClickTime; if (timeDelta < doubleClickTime) { Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { bool foundTarget = false; foreach (string target in targetsTag) { if (hit.transform.CompareTag(target)) { cam.SetTarget(hit.transform); foundTarget = true; } } } lastClickTime = 0; } else { lastClickTime = Time.time; } } }
private void Update() { if (Input.GetMouseButtonDown(0)) { // cant click through UI now if (EventSystem.current.IsPointerOverGameObject()) { return; } Ray ray = camera.ScreenPointToRay(Input.mousePosition); Transform tmp = null; RaycastHit hit; if (Physics.Raycast(ray, out hit)) { tmp = FindParentWithTag2(hit.transform, targetsTag); if (tmp != null) { cam.SetTarget(tmp); } else { cam.ResetTarget(); } } } }
private void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.CompareTag(targetsTag[0]) //|| hit.transform.CompareTag(targetsTag[1]) //|| hit.transform.CompareTag(targetsTag[2]) ) { cam.ResetTarget(); cam.SetTarget(hit.transform); } else { cam.ResetTarget(); } } } }
private void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null) { if (hit.transform.CompareTag(targetsTag)) { cam.SetTarget(hit.transform); } else { cam.ResetTarget(); } } } }
private void Update() { if (!Input.GetMouseButtonDown(0)) { return; } var ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (!Physics.Raycast(ray, out hit)) { return; } if (hit.transform.CompareTag(targetsTag)) { cam.SetTarget(hit.transform); } else { cam.ResetTarget(); } }
private void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { bool foundTarget = false; foreach (string target in targetsTag) { if (hit.transform.CompareTag(target)) { cam.SetTarget(hit.transform); foundTarget = true; } } if (!foundTarget) { cam.ResetTarget(); } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButton(1)) { if (CameraCaster.Instance.SelectedDestination() != null) { characterAgent.MoveToLocation((Vector3)CameraCaster.Instance.SelectedDestination()); } } if (Input.GetMouseButtonDown(0)) { characterAgent.Execute(); } if (Input.GetKeyDown(KeyCode.B) && currentCommand == 'I') { currentCommand = 'B'; } if (Input.GetKeyDown(KeyCode.A) && currentCommand == 'I') { currentCommand = 'A'; characterAgent.BasicAttackInitiate(); } /* Future action implementation * if (Input.GetKeyDown(KeyCode.Q) && currentCommand == 'I'){ * currentCommand = 'Q'; * characterAgent.ActionEnable(currentCommand); * } * if (Input.GetKeyDown(KeyCode.W) && currentCommand == 'I'){ * currentCommand = 'W'; * characterAgent.ActionEnable(currentCommand); * } * if (Input.GetKeyDown(KeyCode.E) && currentCommand == 'I'){ * currentCommand = 'E'; * characterAgent.ActionEnable(currentCommand); * } * if (Input.GetKeyDown(KeyCode.R) && currentCommand == 'I'){ * currentCommand = 'R'; * characterAgent.ActionEnable(currentCommand); * } */ //// Cancel //// if (Input.GetKeyDown(KeyCode.Escape) && currentCommand == 'I') { Application.Quit(); } else if (Input.GetKeyDown(KeyCode.Escape) && currentCommand != 'B') { characterAgent.CancelCommand(); currentCommand = 'I'; } //// Build Command //// if (currentCommand == 'B') { GameController.Instance.Build(); } //// Camera Control //// if (Input.GetKeyDown(KeyCode.Space)) { rtscamera.SetTarget(selectedCharacter.transform); } if (Input.GetKeyUp(KeyCode.Space) || (cameraJump)) { rtscamera.ResetTarget(); cameraJump = false; } //// Character Selection //// if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1)) { rtscamera.SetTarget(character01.transform); selectedCharacter = character01; characterAgent = character01.GetComponent <CharacterAgent>(); cameraJump = true; } if (Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Keypad2)) { rtscamera.SetTarget(character02.transform); selectedCharacter = character02; characterAgent = character02.GetComponent <CharacterAgent>(); cameraJump = true; } if (Input.GetKeyDown(KeyCode.Alpha3) || Input.GetKeyDown(KeyCode.Keypad3)) { rtscamera.SetTarget(character03.transform); selectedCharacter = character03; characterAgent = character03.GetComponent <CharacterAgent>(); cameraJump = true; } if (Input.GetKeyDown(KeyCode.Alpha4) || Input.GetKeyDown(KeyCode.Keypad4)) { rtscamera.SetTarget(character04.transform); selectedCharacter = character04; characterAgent = character04.GetComponent <CharacterAgent>(); cameraJump = true; } }