Question by
Bokhodir · May 26, 2017 at 05:04 AM ·
unity 5switch-case
I would like to return the Z block, if z block is chosen then, the user should have 3 chances to change the block
string GerRandomLetters(){
int randomLetters = Random.Range (1, 8);//getting random numbers to swich
string randomLettersName = "Prefabs/Letter_J"; //setting default
switch (randomLetters) { //switching the numbers
case 1:
randomLettersName = "Prefabs/Letter_J";
break;
case 2:
randomLettersName = "Prefabs/Letter_L";
break;
case 3:
randomLettersName = "Prefabs/Letter_long";
break;
case 4:
randomLettersName = "Prefabs/Letter_S";
break;
case 5:
randomLettersName = "Prefabs/Letter_square";
break;
case 6:
randomLettersName = "Prefabs/Letter_T";
break;
case 7:
randomLettersName = "Prefabs/Letter_Z";
if (Input.GetKeyDown (KeyCode.Space)) {//if user presses the space
for (int i = 0; i < 3; i++) {//user can change 3times
int randomLettersSecond = Random.Range (1, 7);
string randomblockName = "Prefabs/Letter_J";
switch (randomLettersSecond) {
case 1:
randomblockName = "Prefabs/Letter_J";
break;
case 2:
randomblockName = "Prefabs/Letter_L";
break;
case 3:
randomblockName = "Prefabs/Letter_long";
break;
case 4:
randomblockName = "Prefabs/Letter_S";
break;
case 5:
randomblockName = "Prefabs/Letter_square";
break;
case 6:
randomblockName = "Prefabs/Letter_T";
break;
}
return randomblockName; //returning the second switch
}
break;
}
return randomLettersName; //returning the main switch
}
}
Comment
Your answer
Follow this Question
Related Questions
Unhandled Exception: System.StackOverflowException when using Switch Statement? 1 Answer
How to see which Audio Source is using which Audio Mixer 0 Answers
Project won't open with out of memory error 3 Answers
How to change Sprite Image when it reaches 90 degrees? 0 Answers
Unity C# Casual Jewel Mining Game - Jewel Unaffected by Claw 1 Answer