private void Shoot() { Vector3 approxTarget = targetPlayer.transform.position; approxTarget.x += Random.Range(-aistats.accuracy, aistats.accuracy); approxTarget.z += Random.Range(-aistats.accuracy, aistats.accuracy); approxTarget.y = transform.position.y; if (debugMode) { Debug.DrawLine(transform.position, approxTarget, Color.red); } tankController.AimAtPoint(approxTarget.x, approxTarget.z); tankController.Shoot(); }
private void FixedUpdate() { // Movement if (moveInput != Vector2.zero) { tankController.Move(moveInput.x, moveInput.y); } // Aim if (mousePosition != Vector2.zero) { if (currentControlScheme == "Keyboard&Mouse") { Ray ray = cam.ScreenPointToRay(mousePosition); if (debugMode) { Debug.DrawRay(ray.origin, ray.direction * 50, Color.yellow); } RaycastHit hit; if (Physics.Raycast(ray, out hit, 50)) { tankController.AimAtPoint(hit.point.x, hit.point.z); } } else if (currentControlScheme == "Gamepad") { if (mousePosition != Vector2.zero) { if (debugMode) { Debug.DrawRay(transform.position, new Vector3(mousePosition.x, 0, mousePosition.y) * 50, Color.yellow); } tankController.AimAtDirection(mousePosition.x, mousePosition.y); } } else { Debug.LogWarning("Unknown control scheme, unable to handle."); } } if (fireInput == true) { tankController.Shoot(); } }