Hi everyone,
I’m trying the new input system and I am confused on how it works.
I have assigned the alt-left as a Button for interaction. To interact with a door I have to assign playerController.OnDisable(); and playerController.OnEnable(); otherwise the if-statement is applied several time in a row and not just once.
bool openDoor;
void Update()
{
if (playerController.interacting != 0)
{
openDoor = true;
playerController.OnDisable();
}
else
{
openDoor = false;
playerController.OnEnable();
}
if (openDoor)
{
CheckInteract();
}
}
Do I need the playerController.OnEnable(); and playerController.OnDisable(); lines? Shouldn’t be automatic by having Interact as a Button?
This is the part in the PlayerController script which is called:
public class PlayerController : MonoBehaviour, PlayerInput.IPlayerActions
{
private Vector2 moving;
private Vector2 looking;
public float interacting;
private float running;
private PlayerInput keyboardControls;
void Awake()
{
keyboardControls = new PlayerInput();
/* keyboardControls.Player.Move.performed += ctx => OnMove(ctx);
keyboardControls.Player.Look.performed += ctx => OnLook(ctx);
keyboardControls.Player.Jump.performed += ctx => OnJump(ctx);
keyboardControls.Player.Jump.performed += ctx => OnRun(ctx);*/
keyboardControls.Player.SetCallbacks(this);
}
/*...*/
public void OnEnable()
{
keyboardControls.Player.Enable();
}
public void OnDisable()
{
keyboardControls.Player.Disable();
}
public void OnMove(InputAction.CallbackContext context)
{
moving = context.ReadValue<Vector2>();
}
public void OnLook(InputAction.CallbackContext context)
{
looking = context.ReadValue<Vector2>();
}
public void OnInteract(InputAction.CallbackContext context)
{
interacting = context.ReadValue<float>();
}
public void OnRun(InputAction.CallbackContext context)
{
running = context.ReadValue<float>();
}
}