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 question was closed Jan 05, 2019 at 02:26 PM by WeaselBandit for the following reason:

Question was not the problem with the code

avatar image
0
Question by WeaselBandit · Jan 05, 2019 at 02:43 AM · buttonienumeratoronclickstartcoroutine

How to begin startcoroutine (IEnumerator) with UI button.

I've been trying to find an answer (that I can understand) for this for a couple of hours but I haven't been able to find anything.

I'm a very new beginner and I'm following this tutorial: https://www.youtube.com/watch?v=-GWwfBqmWaA∈dex=7&list=PLTm4FjoXO7ndjPE8JXrJ9MjMfsJv956Qm

Only, I would like to get get the username and password from inputfields instead of public strings and I'd like to submit by clicking a UI button instead of using "if(Input.GetKeyDown(KeyCode.L))"

Only I haven't been able to.



What I've tried:

- using button.onclick inside the Update() method... but I can't for the life of me figure out how to use that function.

- creating a separate method to try to start the co routine from the UI button onClick system.

I'm not completely sure how a coroutine and IEnumerator works but I know that I need it to be able to wait for the www variable to finish.

Here's the code I'm currently not able to get working.

 public InputField inputUsername;
 public InputField inputPassword;

 string LoginURL = "http://localhost/languinator/login.php";

 // Start is called before the first frame update
 void Start()
 {
     
 }

 // Update is called once per frame
 void Update()
 {
     //if (Input.GetKeyDown(KeyCode.L)) StartCoroutine(LoginToDB(inputUsername, inputPassword));
 }

 IEnumerator LoginToDB(string username, string password)
 {
     WWWForm form = new WWWForm();
     form.AddField("usernamePOST", username);
     form.AddField("passwordPOST", password);

     WWW www = new WWW(LoginURL, form);

     yield return www;

     Debug.Log(www.text);
 }

 void LoginMethod()
 {
     LoginToDB(inputUsername.text, inputPassword.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

  • Sort: 
avatar image
1

Answer by OGDE01 · Jan 05, 2019 at 03:36 AM

What you should be able to do is create a new public void. In the void, you can call your coroutine. Then, in the inspector, select your button and expand the "Button" component. If you scroll to the bottom, the OnClick method for the button is run here. Click + and drag the object with this script into the Object field. Then, click the button **NEXT* * to where it says runtime and select the script, and select the new method you created. If you need me to explain further, please say so.

Hope this helps!

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

118 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 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

I can't start a coroutine. I get a weird message from visual studio 1 Answer

i want my star () function to work my button is clicked 0 Answers

Can anyone tell me why script is not working? 2 Answers

Button OnClick() only being called once? 3 Answers

[Solved] Button OnClick properties are missing after loading the scene 4 Answers


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