-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputManager.cs
More file actions
38 lines (30 loc) · 1.19 KB
/
InputManager.cs
File metadata and controls
38 lines (30 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class InputManager : MonoBehaviour
{
public static PlayerInput PlayerInput;
private InputAction _mousePositionAction;
private InputAction _mouseAction;
public static Vector2 MousePosition;
public static bool WasLeftMouseButtonPressed;
public static bool WasLeftMouseButtonReleased;
public static bool IsLeftMousePressed;
// Nota: código compatible con inputs desde PC y Android
// Awake: obtención de la fuente de input del jugador
private void Awake()
{
PlayerInput = GetComponent<PlayerInput>();
_mousePositionAction = PlayerInput.actions["MousePosition"];
_mouseAction = PlayerInput.actions["Mouse"];
}
// Update: obtención de acciones del ratón / pantalla táctil
private void Update()
{
MousePosition = _mousePositionAction.ReadValue<Vector2>();
WasLeftMouseButtonPressed = _mouseAction.WasPressedThisFrame();
WasLeftMouseButtonReleased = _mouseAction.WasReleasedThisFrame();
IsLeftMousePressed = _mouseAction.IsPressed();
}
}