So Here is the Problem, You Cant add and remove Units to a Specific List Under the Current Circumstances:
- Removing and adding in same function Input.GetKey(KeyCode.). if u use the same KeyCode
- Removing Using KeyCodeDown(KeyCode.) and Adding Using KeyCodeUp(KeyCode.), if its in the same function
- Removing Using KeyCodeDown(KeyCode.) and Adding Using KeyCodeUp(KeyCode.), even if its in a different Function
- Removing Using KeyCodeDown(KeyCode.) and Adding Using KeyCodeUp(KeyCode.), even if its in a different Function and you wait a few seconds Before you Let go of the Key
- And this is the Worst Part: Even if you use “IEnumerator” functions to add a time gap between the two Via “yield return new WaitForSeconds((5))”, no matter the duration.
- Even if you use “IEnumerator” functions to add a “waitUntill” the Purged list becomes empty “yield return new WaitUntil(() => SelectionManager.ctrlGroup1.Count == 0);”
- If you try to Remove Object A and B and C, while Adding Different Objects D, E and F. It still wont work using any of the Above methods!
NOTE: All of the Above work, if you Initially attempted to Purge/empty a List that was Initially Empty!
Now, I can Understand why method 1 - 2 and 3 dont work. but for the following reasons, I do not Understand why 4 - 5 and 6 Dont work.
Reason 1) if you Separate the two functions Via 2 separate keys, it always works even if you click them very fast in succession.
Reason 2) if you are removing Object A and B and C and trying to Add the Same Objects with the same function, thats something I can Understand. but I am not adding the same functions!
Reason 3) if I use “IEnumerator” to separate the actions by time it still doesn’t work, but if I do it manually using different KeyCode it works no matter how full the list is, and no matter how fast I click the two keys in succession. even if I am adding and removing the exact same items.
Now the way I am going to have to go around this to make my script work, Is make 2 Lists with around 4 loops that must work Like clock work. Though Theoretically I can make this work, It opens so much room for error/Bugs.
I am Obviously Missing Something!. Please help!
This is the Code of my Last Attempt! but I honestly tried this over 20-30 Different ways, It always comes up with the same Error if the above points apply!
IEnumerator SaveToList1()
{
if (Input.GetKey("left shift"))
{
foreach (Unit myUnit in SelectionManager.SelectedUnitList)
{
SelectionManager.ctrlGroup1.Add(myUnit);
Debug.Log("FurtherUnits Have Been Added to group 1");
}
}
else
foreach (Unit myUnit in SelectionManager.ctrlGroup1) //Unless Shift is pressed
{
if (myUnit.tag == ("UnSelected"))
{
SelectionManager.ctrlGroup1.Remove(myUnit);
Debug.Log("Purge-All-Unselected Units-Add");
}
}
if (SelectionManager.ctrlGroup1.Count != 0)
{
yield return new WaitUntil(() => SelectionManager.ctrlGroup1.Count == 0); //Even This Doesnt work "yield return new WaitForSeconds((5)), desipt the list getting purged almost instantly
SaveToList1Part2();
}
else
SaveToList1Part2();
}
void SaveToList1Part2()
{
foreach (Unit myUnit in SelectionManager.SelectedUnitList)
{
SelectionManager.ctrlGroup1.Add(myUnit);
Debug.Log("All-Selected Units Have been Saved to Group1");
}
}
Error: