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)

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.

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,

The best way to do this is a wrapper method.

public void MyButtonClick () {
    // call some other function
}

on Unity Editor, inspector>add component>event trigger