public class PlayerController : MonoBehaviour
{
public float moveSpeed;
private Rigidbody myRigidBody;
private Vector3 moveInput;
private Vector3 moveVelocity;
private Camera mainCamera;
public GunController theGun;
// Start is called before the first frame update
void Start()
{
myRigidBody = GetComponent<Rigidbody>();
mainCamera = FindObjectOfType<Camera>();
}
// Update is called once per frame
void Update()
{
moveInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
moveVelocity = moveInput * moveSpeed;
Ray cameraRay = mainCamera.ScreenPointToRay(Input.mousePosition);
Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
float rayLength;
if(groundPlane.Raycast(cameraRay,out rayLength))
{
Vector3 pointToLook = cameraRay.GetPoint(rayLength);
Debug.DrawLine(cameraRay.origin, pointToLook, Color.blue);
transform.LookAt(new Vector3(pointToLook.x, transform.position.y, pointToLook.z));
}
if(Input.GetMouseButtonDown(0))
print ("The Gun should have fired");
Debug.Log("Pressed Left Mouse Button.");
theGun.isFiring = true;
if (Input.GetMouseButtonDown(0))
print("The gun should have stopped firing");
theGun.isFiring = false;
}
void FixedUpdate()
{
myRigidBody.velocity = moveVelocity;
}
}
Я считаю, что моя проблема начинается с оператора if, if.Кажется, консоль постоянно регистрирует левую кнопку мыши как нажатую.и без оператора отладки, если я нажимаю вниз, всплывающий текст всплывает, но сразу же переходит к следующему отпечатку, даже если я никогда не щелкнул.С отладочным или печатным кодом или без него, ожидаемый эффект никогда не произойдет.Извините, если отформатирован неправильно, очень плохо знаком с этим.
Консоль отладки