private void OnSceneGUI() { FieldOFView fow = (FieldOFView)target; Handles.color = Color.white; Handles.DrawWireArc(fow.transform.position, Vector3.up, Vector3.forward, 360, fow.viewRadius); Vector3 viewAngleA = fow.DirFromAngle(-fow.viewAngle / 2, false); Vector3 viewAngleB = fow.DirFromAngle(fow.viewAngle / 2, false); Handles.DrawLine( fow.transform.position, fow.transform.position + viewAngleA * fow.viewRadius); Handles.DrawLine( fow.transform.position, fow.transform.position + viewAngleB * fow.viewRadius); Handles.color = Color.white; /* * foreach (Transform visibleTarget in fow.visibleTargets) * { * Handles.DrawLine(fow.transform.position, visibleTarget.position); * } */ Handles.color = Color.green; if (fow.getClosestEnemy()) { Handles.DrawLine(fow.transform.position, fow.getClosestEnemy().transform.position); } }
public void ShootRaycastBullet() { shootDir = gunEndPosition.forward; RaycastHit raycastHit; if (Physics.Raycast(gunEndPosition.transform.position, shootDir, out raycastHit, playerManager.playerStat.attackRange)) { if (raycastHit.transform.gameObject.GetComponent <IAttackable>() != null) { playerManager.OnProjectileCollided(raycastHit.transform.gameObject); CreateWeaponTracer(gunEndPosition.transform.position, fieldOFView.getClosestEnemy().position); } else { CreateWeaponTracer(gunEndPosition.transform.position, raycastHit.point); } MuzzleFlashAnimation(); PlayerManager.Instance.ShootingAnimation(); } }
void Update() { #region Joystick and Movement Controllers //gets the movement of the joystick if (!keyboardPlay) { if (uiGameplay == null) { return; } if (uiGameplay.joystick.Horizontal >= 0.3f) { horizontalMove = speed; } else if (uiGameplay.joystick.Horizontal <= -0.3f) { horizontalMove = -speed; } else { horizontalMove = 0f; } if (uiGameplay.joystick.Vertical >= 0.3f) { verticalMove = speed; } else if (uiGameplay.joystick.Vertical <= -0.3f) { verticalMove = -speed; } else { verticalMove = 0f; } //gets the movement and moves the agent Vector3 movement = new Vector3(horizontalMove, 0f, verticalMove); Vector3 moveDestination = transform.position + movement; agent.destination = moveDestination; if (movement != Vector3.zero) { Vector3 dir = moveDestination - transform.position; if (fieldOFView.getClosestEnemy() == null) { dir.y = 0; Quaternion rot = Quaternion.LookRotation(dir); transform.rotation = Quaternion.Lerp(transform.rotation, rot, rotationSpeed * Time.deltaTime); } else if (fieldOFView.getClosestEnemy()) { transform.LookAt(fieldOFView.getClosestEnemy().transform.position); } } if (fieldOFView.getClosestEnemy() != null && !uiGameplay.touchField.Pressed) { transform.LookAt(fieldOFView.getClosestEnemy().transform.position); } } #endregion #region Mouse and Keyboard Controllers // I dont have a smartphone, have to use keyboard input. if (keyboardPlay) { KeyboardInputMovement.x = (Input.GetAxisRaw("Horizontal")); KeyboardInputMovement.z = (Input.GetAxisRaw("Vertical")); Vector3 moveDestination = transform.position + KeyboardInputMovement; agent.destination = moveDestination; Ray CameraRay = Camera.main.ScreenPointToRay(Input.mousePosition); Plane groundPlane = new Plane(Vector3.up, Vector3.zero); float rayLenght; if (!fieldOFView.getClosestEnemy()) { if (groundPlane.Raycast(CameraRay, out rayLenght)) { Vector3 pointToLook = CameraRay.GetPoint(rayLenght); transform.LookAt(pointToLook); } } else if (fieldOFView.getClosestEnemy()) { transform.LookAt(fieldOFView.getClosestEnemy().transform.position); } } #endregion #region Rotation if (uiGameplay.touchField.Pressed) { Vector3 dir = uiGameplay.touchField.TouchDist; Vector3 rot = new Vector3(0, dir.x); transform.Rotate(rot); } #endregion }