So yesterday I’ve been drinking and playing drinking games, and thought it would be fun to make my own.
Unfortunately I’ve taken a break from Unity, and have forgot most of the things I knew, so I have some questions, and hopefully you guys can point to the right direction.
First question: I have a field where the person participating in the game types in his name. I want to have a + sign under in case there are more people, to add a new field for a name. How would I go around to do that?
Second question: I want the “game” to be simple. You tap your phone screen, a text comes up with a command for a random player to do. How would I have to do it, that a random text that I’ve written before pops up, and after tapping the screen again, a new text pops up, and so on.
For your second question, it sounds like you’re going to want some kind of networking component, as it sounds like you want several players nearby each other to all play in a shared match. That’s going to be quite a bit more complicated, and not something someone here is going to be able to walk you through 100%. Probably these days you’d want to look into using Photon, or some 3rd party solution, as Unity’s built-in networking feature is currently deprecated and going to be replaced in the near future.
Thank you for your answer. I think I might’ve explained wrong. For the second question, it’s much more simpler than that. Only one phone is needed, but each time a new text is pulled up, a random name is inserted from a list you had to fill in before hand.
And for the other thing, I want it so that when the + is pressed like shown in the picture, another input field pops up where you can insert another player. I haven’t been able to find this info in the video you’ve sent. Thank you!
Fair enough. Well, I wouldn’t expect you to find a tutorial that explains how to do exactly what you’re trying to do. Your approach would depend on how you’ve set up your UI. Also, on these forums, you’ll have better luck if you show what you’ve tried, and ask specific technical questions regarding what isn’t working for you.
In general, for your “+” button, the easiest approach would be to have some number of text-boxes already in your UI, arranged in a Vertical Layout Group, along with the + button. All but the first textbox would have their game object initially disable (that is, call SetActive(false) in Start, or just disable the gameObject in the editor). Upon pressing the + button, you can set the next inactive textbox to active to “show” it. There’s all sorts of other stuff you could do, like adding a “-” to delete one, and doing cool animation stuff to make the new textbox appear in a prettier way, but that’s the basic approach. You could also dynamically create the UI instead of pre-creating it if the max number of possible people was very high.
For your other question, I’m still not really clear on what that experience will feel like, but if your list is the list of names you entered with the + button textboxes, then you can do something like this:
Add a change event to the text box so that it calls a function in your controller whenever the text changes
In that function, get the values from all the textboxes, and use those values to update an internal list of names.
When you need a random name, using UnityEngine.Random.Range() to randomly pick a name from the list.