- Home /
Question by
The-Z-axis · Jun 17, 2019 at 05:17 AM ·
inputbuttonkeyboard input
Enable/Disable button input
So here's what I'm trying to do-
I want to create a boolean that determines weather or not a key's input will actually go through. This particular key is used in several different scripts and I don't want to have to change all 11 of them and would rather just enable/disable the key itself.
I should also note it's not linked to a specific key on the keyboard, it has its own button name and everything. If someone can give me an answer I would be endlessly grateful.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CanSwap : MonoBehaviour
{
public bool enableSwapping;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (enableSwapping == true)
{
//Enable the "Swap Dimensions" button
}
else
{
//Disable the "Swap Dimensions" button
}
}
}
Comment
Answer by EternalClickbait · Jun 17, 2019 at 06:50 AM
Just use either a Singleton or a static class (my preference). THen, wherever it's used, just check the value of the 'Special' class. e.g.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CanSwap : MonoBehaviour
{
void Start()
{
}
// Update is called once per frame
void Update()
{
if (StaticClass.SwappingEnabled)
{
//Enable the "Swap Dimensions" button
}
else
{
//Disable the "Swap Dimensions" button
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612203332im_/https://answers.unity.com/themes/thub/images/avi.jpg)