Uppdatering av PlayerControls
This commit is contained in:
@@ -16,6 +16,8 @@ public class BallController : MonoBehaviour {
|
||||
float _jumpForce;
|
||||
Rigidbody _ball;
|
||||
float _outOfBounds = -1.8f;
|
||||
private Vector2 _moveInput;
|
||||
private PlayerControls _controls;
|
||||
|
||||
void Start() {
|
||||
_ball = GetComponent<Rigidbody>();
|
||||
@@ -25,9 +27,43 @@ public class BallController : MonoBehaviour {
|
||||
_pickupLeft = GameObject.FindGameObjectsWithTag("PickUp").Length;
|
||||
transform.position = new Vector3(0, 0.5f, 0);
|
||||
}
|
||||
private void Awake() {
|
||||
_controls = new PlayerControls();
|
||||
}
|
||||
private void OnEnable() {
|
||||
_controls.Enable();
|
||||
|
||||
_controls.Player.Move.performed += ctx =>
|
||||
_moveInput = ctx.ReadValue<Vector2>();
|
||||
|
||||
_controls.Player.Move.canceled += ctx =>
|
||||
_moveInput = Vector2.zero;
|
||||
|
||||
_controls.Player.Jump.performed += ctx => {
|
||||
Debug.Log("SPACE TRYCKT");
|
||||
if (transform.position.y < 1) {
|
||||
_ball.AddForce(Vector3.up * _jumpForce);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void OnMove(InputAction.CallbackContext context) {
|
||||
_moveInput = context.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
private void FixedUpdate() {
|
||||
Vector3 direction =
|
||||
new Vector3(_moveInput.x, 0, _moveInput.y);
|
||||
|
||||
_ball.AddForce(direction * _ballSpeed);
|
||||
|
||||
if (direction == Vector3.zero) {
|
||||
_ball.AddForce(-_ball.linearVelocity * _brakeForce);
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
KeyHandler();
|
||||
//KeyHandler();
|
||||
CheckPlayerOut();
|
||||
UpdateGUI();
|
||||
}
|
||||
@@ -60,6 +96,7 @@ public class BallController : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void KeyHandler() {
|
||||
if (Keyboard.current.wKey.isPressed) {
|
||||
_ball.AddForce(Vector3.forward * _ballSpeed);
|
||||
@@ -80,4 +117,5 @@ public class BallController : MonoBehaviour {
|
||||
_ball.AddForce(-_ball.linearVelocity * _brakeForce);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user