-3

I have a script that has 2 public KeyCode variables the developer can set. What I want to accomplish is when say the dev selects as the player attack to be "Space" I would like to have the next public KeyCode selection "Interaction" to not include "Space" in its selection as what I am trying to accomplish is that no 2 KeyCodes can be set to the same Key.

I know I could put in place a check in OnValidate and create a warning in the console that it needs to be changed. But as I am making tools for developers I want to avoid that road anyway possible and just have them on rails that wont break if that makes sense.

JoeyL
  • 1,295
  • 7
  • 28
  • 50

1 Answers1

1

Fil an List or Array with all the keys that could have been selected, and for every selected key you remove is from the List/Array.

Then you have a new List or Array only with the keys that you can select.

You only have to rework a little bit of this in your own way. (C# unity code)

using System;
using System.Collections.Generic;

public class KeySelector 
{
    public List<KeyCode> selection;

    public void AddKey(KeyCode)
    {
        selection.Add(KeyCode);
    }

    public void RemoveKey(KeyCode)
    {
        selection.Remove(KeyCode);
    }

    //Foreach Keycode in selection (To make the list that the dev can choose of)
    foreach(Keycode key in selection)
    {
        //TODO write code to make a list
    }
}
NLxDoDge
  • 189
  • 2
  • 13