PBG2H23ABR_PBG2H23AKL_PMC_P.../Plunderblock/Assets/Scripts/ScriptsJan/InputScripts/NewKeybindScript.cs

49 lines
1.4 KiB
C#
Raw Permalink Normal View History

2024-08-13 21:11:05 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewKeybindScript : MonoBehaviour
{
private bool keybindWasChanged = true;
[SerializeField] private string actionName;
private KeyCode newKey;
private InputManagerScript i;
// Start is called before the first frame update
void Start()
{
i = GameObject.Find("InputManager").GetComponent<InputManagerScript>();
}
// Update is called once per frame
void Update()
{
remapKey();
}
public void remapKey()
{
if(keybindWasChanged == false)
{
if (Input.anyKey) // if a key is pressed
{
foreach (KeyCode kcode in System.Enum.GetValues(typeof(KeyCode))) // goes through all keys to find out which was pressed
{
if (Input.GetKey(kcode))
{
i.remapKey(actionName, kcode); // function from InputManager (changes key)
keybindWasChanged = true;
this.gameObject.SetActive(false); // makes the UI for changing the Key disappear
break;
}
}
}
}
}
public void setChangingKey(string actionName)
{
keybindWasChanged = false;
this.actionName = actionName;
}
}