Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by DiabolusGX · Mar 04, 2019 at 06:12 PM · inputfieldgui-button

Assign a hotkey to a GUI button

I want to press "Enter" to take input from input field instead of clicking on submit button or anything like that and also I want that the next input field get selected automatically for input. I don't want to take input from both input fields at same time by pressing "Enter" only once i.e. first 1st input field will take input then I'll press Enter and next input field gets selected for input and then I'll put data and press Enter to get input from 2nd input field. PLEASE find solution for this Also where to add script for this? please help ! Thank You

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class Input1 : MonoBehaviour
 {
     public InputField name1;
     public InputField name2;
    public void get1()
     {
         fword1.text = name1.text + "'s word is '" + word1.text + "'";
     }
     public void get2()
     {
         fword2.text = name2.text + "'s word is '" + word2.text + "'";
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by WarmedxMints · Mar 04, 2019 at 06:59 PM

You can use Unity's built-in event system to check which gameobject is currently selected and then do something if return is pressed while it is.

 using UnityEngine;
 using UnityEngine.EventSystems;
 using UnityEngine.UI;
 
 public class Input1 : MonoBehaviour
 {
     public InputField name1;
     public InputField name2;
 
     private void Update()
     {
         if(Input.GetKeyDown(KeyCode.Return))
         {
             //If field one is selected
             if(EventSystem.current.gameObject == name1.gameObject)
             {
                 //Set field 2 active
                 EventSystem.current.SetSelectedGameObject(name2.gameObject);
             }
             //If enter is pressed when field2 is selected
             if (EventSystem.current.gameObject == name2.gameObject)
             {
                 //Whatever you wish to do when return is pressed on field 2
             }
         }
     }
 }
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DiabolusGX · Mar 04, 2019 at 09:03 PM 0
Share

thanks for answer but where to add this script? I mean on Button? or where? because I was using OnClick Get() function previously to print data. alt text

capture.png (25.5 kB)
avatar image WarmedxMints DiabolusGX · Mar 04, 2019 at 11:03 PM 0
Share

Just add the update method to your current Input1 script.

avatar image DiabolusGX WarmedxMints · Mar 05, 2019 at 05:13 AM 0
Share

NOT WOR$$anonymous$$INGalt text

capture.png (55.9 kB)
Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

103 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Keyboard only working in Development Build. GUI Button only working in non-Development Build 0 Answers

GUI Button to toggle true false when pressed 1 Answer

button pressed twice / Conversation text skip 5 Answers

GUI problem 1 Answer

how can i change the gui button on runtime?? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges