// Example CodepublicvoidOnMyAction(InputAction.CallbackContext context){if (context.started) {Debug.Log("Action was started"); }elseif (context.performed) {Debug.Log("Action was performed"); }elseif (context.canceled){Debug.Log("Action was cancelled"); }}
For our project:
publicvoidOnInteract(InputAction.CallbackContext ctx){if (ctx.started) {Debug.Log("DiaManager Should Open"); }}
Script adapted from Ruby's Adventure
RaycastHit2D hit =Physics2D.Raycast(rb.position+Vector2.up, lookDirection,1.5f,LayerMask.GetMask("Interactibles"));if (hit.collider!=null){DiaTrigger character =hit.collider.GetComponent<DiaTrigger>();if (character !=null) {character.Begin(); }}
Disabling Movement for UI
To switch to UI, you can change the Action Map. You need to set the default action map in the previous section first before switching.
This Interact function will trigger the DiaManager's "Show" function (This is the UI controller for the dialogue box). That is when we want to stop the player from moving.
usingUnityEngine.InputSystem;...privatePlayerInput playerInput;//Initial State of the GameprivatevoidStart() { //I've put the playerInput component on the Player GameObject, hence the tag playerInput =GameObject.FindWithTag("Player").GetComponent<PlayerInput>();}publicvoidShow(...){Debug.Log("DiaManager Should Open");playerInput.SwitchCurrentActionMap("UI");}