Changing the Input with buttons?

Hello everybody! At the 101Text lesson ,do you guys have any ideea how can I change the input method from GetKeyDown to something like Onbuttonclick? i would like to make the answer states in the form of buttons.Thank you!

Hi Denis_Maria_Boghean,

Welcome to our community! :slight_smile:

Maybe you could watch the Number Wizard UI section first. Then you’ll very be likely to modify your adventure game so the player will be able to click on buttons.

If you want to try to learn this yourself (it’s very simple), you could watch a video on Youtube such as this one. If the video is not clear (I didn’t watch it), look for “Unity Button Tutorial” on Youtube.

Did this help?


See also:

Hey @Nina !
Thank you for replying!
I would do my buttons prefabs.Because i have a different scripts on each button(like add health to the player,or other button add exp to the player)So…i would like to add in the scriptable object …when you press New states to appear on each element another child element with a empty gameobj to drag my button prefab.To be more exact ,the posibility on each element from the vector to add another element.I dont know if im clear enough.A vector in vector? :smile:

I’m not quite sure if I understood you correctly. What do you mean by Vector? I’m asking because there is a Vector2 and a Vector3 struct in Unity.

And for what do you need an empty game object?

Or rather: What exactly is your goal? Not the concept, just the goal! Maybe there is a simpler solution than what you described (and what I might have misunderstood).

OH sorry, @Nina .In my language we call the Arrays -> vectors.
well.hmm…
I want to make a dialog system with multiple choices within my game.
In a button we have a function named onClick ().There, i have my own script.So if button clicked you gain something (at a stat system).
My aproach whould be.
in the scriptable object (State.cs) to make a section of each element like : how many buttons would you like?(and there i should type a number.For example.i want 3.It will spawn 3 empty game objects and there i would like to put my prefab buttons(with theirs individual OnClick() script triggers).)
hope you understand my imagination :))) and I would like to hear your approach!
Thank you!

Maybe you could simplify the concept a bit. What’s the maximum number of option buttons in your entire game? If you know that, you could create a game object with x children where x is the number of buttons. Instead of instantiating buttons, you simply enable or disable them with SetActive(true) and SetActive(false) respectively.

If you know for loops, realising this idea should not be much of a problem. For loops are covered in one of the last videos in the Text 101 section.

If the buttons get different texts during runtime, you don’t hard-code it but access the relevant property which you look up in the API. You do it in a similar way as what you did with the Text component to display your story text.

This way, you won’t have to worry about the references during runtime because you don’t generate any game objects during runtime.

This is a very interesting Ideea! Ill try to implement! Thank you,@Nina!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms