0

Is there a way to take user input and make array of game objects based on the input in Unity™? (For Tower of Hanoi)

12th Apr 2018, 11:38 AM
1604064_Sharif
1604064_Sharif - avatar
5 Respuestas
+ 2
Since this is Unity, how do you plan on taking user input? With a textbox / Button? Or, Keypress?
12th Apr 2018, 4:10 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
You can use the inputField component to get the user to enter text into a box. It has something called 'End Edit (String)', which you can use to call a method from one of your scripts when a user enters something into the text box. Since the input is a number, you can then convert the string to an int, and use it to create an array of that size. *Use a try-catch to make sure the user actually enters a number.* If you're unsure how to do these things hopefully this tutorial will help on how to get user input using inputField: https://youtu.be/tMgC2yH4Kkk Tutorial previous to that one, setting up a canvas for the UI: https://youtu.be/kZji1VJmZXA
12th Apr 2018, 6:59 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
Yes, you can do that as well! As long as you can get the number the user enters with an inputField, you can do whatever you'd like with it. For example, set up a method to create the 'next disk', and use a loop to call it however many times the user wants. 'next disk' would be a method that creates another disk on top of the previous one. If you wanted to, you can still place each disk into an array to keep track of their positions.
12th Apr 2018, 7:07 PM
Rrestoring faith
Rrestoring faith - avatar
0
with a textbox
12th Apr 2018, 6:43 PM
1604064_Sharif
1604064_Sharif - avatar
0
How about making objects based on the input? For example, when 7 is taken as input, 7 disks will appear on screen, one on top of the another.
12th Apr 2018, 7:03 PM
1604064_Sharif
1604064_Sharif - avatar