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 /
  • Help Room /
avatar image
0
Question by necrodrow · Feb 08, 2018 at 02:01 AM · unity 5uibuttonbuttonsonclick

is it possible to have two on click events in one button

good day i am trying to have two onclick events on one button. the first code would add the input fields to a google form but i want the other event to change scenes. This is what i have thus far

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

public class sendtogoogle : MonoBehaviour {

 public GameObject name;
 public GameObject contactnumber;
 public GameObject time;
 public GameObject seating;
 public GameObject email;

 private string Name;
 private string ContactNumber;
 private string Time;
 private string Seating;
 private string Email;

 [SerializeField]
 private string BASE_URL = "https://docs.google.com/forms/d/e/1FAIpQLSeDQ2b7jBRRd8wsmLSOJY9vdhqLbMmBraVFi5FnzM__p3OBsg/formResponse";

 IEnumerator Post (string name, string contactnumber, string time, string seating, string email){
     WWWForm form = new WWWForm();
     form.AddField ("entry.147709443",name);
     form.AddField ("entry.1096821271",contactnumber);
     form.AddField ("entry.98853131",time);
     form.AddField ("entry.1504298736",seating);
     form.AddField ("entry.1983788742",email);
     byte[] rawData = form.data;
     WWW www = new WWW(BASE_URL, rawData);
     yield return www;
 }
 public void Send() {

     Name = name.GetComponent<InputField> ().text;
     ContactNumber = contactnumber.GetComponent<InputField> ().text;
     Time = time.GetComponent<InputField> ().text;
     Seating = seating.GetComponent<InputField> ().text;
     Email = email.GetComponent<InputField> ().text;

     StartCoroutine (Post (Name, ContactNumber, Time, Seating, Email));
 }    

}

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
2
Best Answer

Answer by Vicarian · May 11, 2018 at 03:08 PM

You can add multiple listeners to a button in code:

 void Start() {
     someUIButtonReference.onClick.AddListener(SomeFunction1);
     someUIButtonReference.onClick.AddListener(SomeFunction2);
 }

 void SomeFunction1() {
     Debug.Log("SomeFunction1");
 }

 void SomeFunction2() {
     Debug.Log("SomeFunction2");
 }
 

or you can assign functions for a button click event to process in the editor. alt text

The catch here is that the functions need to be publicly accessible. If you don't want a bunch of public functions, use the code method. The functions are called in the order that they're listed, so in this case SomeFunction1 will precede SomeFunction2.


capture.png (22.3 kB)
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

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

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

UI Button OnClick Only Works the First Time 2 Answers

AddListener not working after build 0 Answers

Giving a UI button a Color at Start 0 Answers

How do I change UI button background AND button text on click(pressed)? 0 Answers

Button Flickering On and Off When Pressed 2 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