Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 RBN · Dec 25, 2014 at 07:11 PM · new ui

Use a function as Unity 4.6 UI event

Hey.

Is it possible to use a function as Unity 4.6 UI event, instead of creating a new public function in an object?

What I mean by this, can I, as example, do this: QualitySettings.SetQualityLevel (0, true);

With the event system? If not, what's the suggested way of doing this?

(PS: With the event system I mean the built in event system where you don't have to script anything but just select and drag anything you want. If you still don't know what I mean, add a button and scroll down until you see OnClick())

(to anybody: if you want, edit any wrong naming I gave to anything. I'm pretty new to unity)

Comment
Add comment · Show 2
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 Mexallon · Dec 25, 2014 at 07:20 PM 0
Share

I don't think so. But I almost everytime create a "XYZClicked()" and execute there what ever is necessary or delegate the work to another script for seperation concerns.

avatar image RBN · Dec 26, 2014 at 09:36 AM 0
Share

I assume that there's no answer to my question, except script it myself. If that's untrue, please write that down below. If not, I'll mark every correct answer below.

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by BMayne · Dec 25, 2014 at 09:29 PM

Hey there,

You can do this without having to write a new function. It's called a Lambda Expression, they are pretty neat. Here is the syntax.

 myButton.onClick.AddListener(()=> 
 { 
    QualitySettings.SetQualityLevel (0, true); 
    Debug.Log("Quality set to Zero");
 });

There is a lot more to learn about these types of expressions so I would suggest reading about them on MSDN.

Regards,

Comment
Add comment · Show 1 · 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 BMayne · Dec 25, 2014 at 09:39 PM 0
Share

I can't read. You wanted to do it with no scripting. In that case you are out of luck. You can expect Unity to use Reflection to find every method in your assembly and let you pick it from a list. You have to give it a reference to what it is calling.

avatar image
1

Answer by Mmmpies · Dec 25, 2014 at 08:34 PM

I know you said without any scripting but you've pretty much scripted what you want right there.

 using UnityEngine;
 using System.Collections;

 public class SetQuality : MonoBehaviour {

 public void SetQualityZero()
 {
     QualitySettings.SetQualityLevel (0, true);
 }
 }

Create a UI button and drag the script onto it. Then add an eventTrigger to the button, PointerClick then click on the + sign. Drag the button into the empty slot and from the drop down select SetQuality -> SetQualityZero()

That's it.

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
avatar image
0

Answer by Kiwasi · Dec 25, 2014 at 08:24 PM

The best way to do this is a wrapper method.

 public void MyButtonClick () {
     // call some other function
 }
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
avatar image
0

Answer by wowipop · Dec 26, 2014 at 04:35 AM

on Unity Editor, inspector>add component>event trigger

Comment
Add comment · Show 2 · 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 RBN · Dec 26, 2014 at 09:34 AM 0
Share

I know what an event trigger is, but could you please explain what you mean? I don't know how to add these functions on there without any scripting. If you could show me that would be great.

avatar image wowipop · Dec 26, 2014 at 09:58 AM 0
Share

sry though it's under the camera. I guess you can't get setting manager as gameobject

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

31 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

Related Questions

smoothly transmogrify an object as it enters a circle 1 Answer

Animated load screen. What is the command to check if a scene is being loaded or the game is transitioning between scenes? 2 Answers

how well does unity work for turn-based game time-type? 3 Answers

Maximum Unity Navmesh Agents? 1 Answer

Working with UI Text in 4.6 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