Menu eingebaut, + Keybind Settings
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class InputManagerScript : MonoBehaviour
|
||||
{
|
||||
|
||||
// Input Options
|
||||
[Header("Input")]
|
||||
[SerializeField] private KeyCode moveRight;
|
||||
[SerializeField] private KeyCode moveLeft;
|
||||
[SerializeField] private KeyCode moveForward;
|
||||
[SerializeField] private KeyCode moveBack;
|
||||
[SerializeField] private KeyCode jump;
|
||||
[SerializeField] private KeyCode shoot;
|
||||
[SerializeField] private KeyCode reload;
|
||||
|
||||
// for the UI of button remaping
|
||||
[SerializeField] private TextMeshProUGUI[] currentKeys;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------- Get Input (for other Scripts) -----------------------------------------
|
||||
public KeyCode getMoveRight()
|
||||
{
|
||||
return moveRight;
|
||||
}
|
||||
|
||||
public KeyCode getMoveLeft()
|
||||
{
|
||||
return moveLeft;
|
||||
}
|
||||
|
||||
public KeyCode getMoveForward()
|
||||
{
|
||||
return moveForward;
|
||||
}
|
||||
|
||||
public KeyCode getMoveBack()
|
||||
{
|
||||
return moveBack;
|
||||
}
|
||||
|
||||
public KeyCode getJump()
|
||||
{
|
||||
return jump;
|
||||
}
|
||||
|
||||
public KeyCode getShoot()
|
||||
{
|
||||
return shoot;
|
||||
}
|
||||
|
||||
public KeyCode getReload()
|
||||
{
|
||||
return reload;
|
||||
}
|
||||
|
||||
//---------------------------------------------- Remap Buttons ----------------------------------------------------
|
||||
public void remapKey(string actionName, KeyCode key) // remaps the action to the new Button and changes it in the UI (keybinding)
|
||||
{
|
||||
switch(actionName)
|
||||
{
|
||||
case "moveRight":
|
||||
moveRight = key; // new Button
|
||||
currentKeys[0].text = key.ToString();
|
||||
break;
|
||||
case "moveLeft":
|
||||
moveLeft = key;
|
||||
currentKeys[1].text = key.ToString();
|
||||
break;
|
||||
case "moveForward":
|
||||
moveForward = key;
|
||||
currentKeys[2].text = key.ToString();
|
||||
break;
|
||||
case "moveBack":
|
||||
moveBack = key;
|
||||
currentKeys[3].text = key.ToString();
|
||||
break;
|
||||
case "shoot":
|
||||
shoot = key;
|
||||
currentKeys[4].text = key.ToString();
|
||||
break;
|
||||
case "reload":
|
||||
reload = key;
|
||||
currentKeys[5].text = key.ToString();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef2f2a0211f2ace4fb0a262d491323f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,56 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MenuScript : MonoBehaviour
|
||||
{
|
||||
[SerializeField] int menuLayer; // Shows at what layer the current Menu is and what esc should do
|
||||
[SerializeField] GameObject defaultMenu;
|
||||
[SerializeField] GameObject settingsMenu;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
escPressed();
|
||||
}
|
||||
|
||||
public void escPressed()
|
||||
{
|
||||
if(Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown("o"))
|
||||
{
|
||||
if(menuLayer == 0)
|
||||
{
|
||||
defaultMenu.SetActive(true);
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
menuLayer = 1;
|
||||
}
|
||||
else if(menuLayer == 1)
|
||||
{
|
||||
defaultMenu.SetActive(false);
|
||||
lockCursor();
|
||||
menuLayer = 0;
|
||||
}
|
||||
else if(menuLayer == 2)
|
||||
{
|
||||
settingsMenu.SetActive(false);
|
||||
defaultMenu.SetActive(true);
|
||||
menuLayer = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setMenuLayer(int i)
|
||||
{
|
||||
menuLayer = i;
|
||||
}
|
||||
|
||||
public void quit()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public void lockCursor()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0100531b5445cc04eb42d8054e43e9c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,48 @@
|
||||
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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00d2815ff536fbb4fa1d8bd94f22131b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user