change: input dialogue on player spawn
This commit is contained in:
35
Assets/Scripts/Core/InputFinder.cs
Normal file
35
Assets/Scripts/Core/InputFinder.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Reset;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class InputFinder : MonoBehaviour{
|
||||
public InputActionMap actionMap;
|
||||
|
||||
void Start(){
|
||||
actionMap.actions[0].performed += ctx => { InputPressed(ctx); };
|
||||
|
||||
GetComponent<UIDocument>().enabled = false;
|
||||
}
|
||||
|
||||
public void AwaitNewInput(){
|
||||
GameManager.ClearCurrentController();
|
||||
|
||||
GetComponent<UIDocument>().enabled = true;
|
||||
actionMap.Enable();
|
||||
}
|
||||
|
||||
void InputPressed(InputAction.CallbackContext context){
|
||||
try {
|
||||
GameManager.AttachControllerToPlayer(context.control.device);
|
||||
Debug.Log(context.control.device);
|
||||
} catch (Exception e) {
|
||||
Debug.LogError($"Failed to set the new device to the player: {e.Message}");
|
||||
return;
|
||||
}
|
||||
|
||||
GetComponent<UIDocument>().enabled = false;
|
||||
actionMap.Disable();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user