private void Update() { Debug.Log(IsGrounded ? "地上にいます" : "空中です"); if (CrossPlatformInputManager.GetButtonDown("Fire1") || Input.GetButtonDown("Fire1")) { // Fire1ボタン(デフォルトだとマウス左クリック)で攻撃 Debug.Log("Fire1ボタン"); _attack.AttackIfPossible(); } if (_status.IsMovable) // 移動可能な状態であれば、ユーザー入力を移動に反映する { // 入力軸による移動処理(慣性を無視しているので、キビキビ動く) _moveVelocity.x = CrossPlatformInputManager.GetAxis("Horizontal") * moveSpeed; _moveVelocity.z = CrossPlatformInputManager.GetAxis("Vertical") * moveSpeed; // 移動方向に向く _transform.LookAt(_transform.position + new Vector3(_moveVelocity.x, 0, _moveVelocity.z)); } else { _moveVelocity.x = 0; _moveVelocity.z = 0; } if (IsGrounded) { if (CrossPlatformInputManager.GetButtonDown("Jump") || Input.GetButtonDown("Jump")) { // ジャンプ処理 Debug.Log("ジャンプ!"); _moveVelocity.y = jumpPower; // ジャンプの際は上方向に移動させる } } else { // 重力による加速 _moveVelocity.y += Physics.gravity.y * Time.deltaTime; } // オブジェクトを動かす _characterController.Move(_moveVelocity * Time.deltaTime); // 移動スピードをanimatorに反映 animator.SetFloat("MoveSpeed", new Vector3(_moveVelocity.x, 0, _moveVelocity.z).magnitude); }
private void Update() { Debug.Log(IsGrounded ? "地上にいます" : "空中です"); if (CrossPlatformInputManager.GetButtonDown("Fire1")) { _attack.AttackIfPossible(); } if (_status.IsMovable) { _moveVelocity.x = CrossPlatformInputManager.GetAxis("Horizontal") * moveSpeed; _moveVelocity.z = CrossPlatformInputManager.GetAxis("Vertical") * moveSpeed; // 移動方向に向く _transform.LookAt(_transform.position + new Vector3(_moveVelocity.x, 0, _moveVelocity.z)); } else { _moveVelocity.x = 0; _moveVelocity.y = 0; } // _moveVelocity.x = CrossPlatformInputManager.GetAxis("Horizontal") * moveSpeed; // _moveVelocity.z = CrossPlatformInputManager.GetAxis("Vertical") * moveSpeed; // _transform.LookAt(_transform.position + new Vector3(_moveVelocity.x, 0, _moveVelocity.z)); if (IsGrounded) { if (Input.GetButtonDown("Jump")) { // ジャンプ処理 Debug.Log("ジャンプ!"); _moveVelocity.y = jumpPower; } else { // 重力による加速 _moveVelocity.y += Physics.gravity.y * Time.deltaTime; } // オブジェクトを動かす _characterController.Move(_moveVelocity * Time.deltaTime); } animator.SetFloat("MoveSpeed", new Vector3(_moveVelocity.x, 0, _moveVelocity.z).magnitude); }