ok im starting to get the hang of many things in C#/unity and i'm trying to pull off something fairly complicated (for me at least):
i want to create a combat on/off toggle method that activates either when pressing “1” , or “mouse 0”.
i've done that with a switch statement that switches between a bool called inCombat:
switch(inCombat)
{
default:
//call combat script
inCombat = true;
break;
case(inCombat):
//stop calling combat script
inCombat = false;
break;
}
the thing is, when i'm in combat, i don't want to disable combat by pressing Mouse0, cause that should attack.
so i wanted to make a switch statement inside the if(Input.GetKeyDown), that checks an array of KeyCodes, and then calculates the outcome based on what key was pressed.
now obviously there are much less convoluted ways of doing this (like dividing it into 2 different methods/ scripts), but since i'm fairly new to C# i wanted to figure out if my original idea is even possible, and if so - how.
adding the InitiateCombat() method's code in it's current state.
private void InitiateCombat()
{
KeyCode[] combatInitiator = new KeyCode[]{KeyCode.Alpha1, KeyCode.Mouse0};
if (Input.GetKeyDown(combatInitiator[]))
{
switch (KeyCode[])
{
case (KeyCode.Alpha1):
switch (inCombat)
{
default:
print("Initiating combat. getting me sword out");
inCombat = true;
print(inCombat);
break;
case (true):
print("already in Combat, getting me sword back");
inCombat = false;
print(inCombat);
break;
}
break;
case (KeyCode.Mouse0):
if (!inCombat)
{
print("Initiating combat. getting me sword out");
inCombat = true;
print(inCombat);
}
else
{
return;
}
break;
}
}
}
thanks guys!