Check for Shift in an If Statement, RTS giving several commands
I want to check wether Shift is pressed before the building is placed, so that "if shift is pressed" another building might get placed. I came up with this code, however it does not seem to get the "shift loop".
if (create== true)
{
tDragHolder.transform.position = (finalPosition);
checkshift:
if (Input.GetMouseButton(0) && gold.gold >= cost && Input.GetKeyDown(KeyCode.LeftShift))
{
Instantiate(TurretB, finalPosition, Quaternion.identity);
gold.gold = gold.gold - cost;
Debug.Log("This Loop got triggered");
goto checkshift;
}
else
{
if (Input.GetMouseButton(0) && gold.gold >= cost)
{
Instantiate(TurretB, finalPosition, Quaternion.identity);
create = false;
Debug.Log("The shift Loop was not triggered.");
tDragHolder.transform.position = Hide;
}
}
This is placed in the Update Method. Also, i have read that goto is ugly to use, but for me as a noob it seemed to be an easy workaround for what im trying to do without too much of code. Sorry fur the circumstances ¯_ (ツ)_/¯
Your answer
Follow this Question
Related Questions
Break the loop when there are no more questions 0 Answers
How to collect all the values of (if) in one ? 3 Answers
How do I delete objects in an animation in a certain order? 1 Answer
Array only detects if last entry in array has a true boolean 0 Answers
The bool activates and deactivates but the script in the if statement doesn´t work 1 Answer