First of all, this plug-in is a plug-in that implements the virtual joystick,
First, there is an easy button. Here we will talk about two of its events. The other methods like how to obtain components are similar to ngui and ugui. The easy button has two events, they are massage and event. Here we mainly talk about event. event is a delegate in C #. What is a delegate? You can read the C # book.
Here we write a script,
Using unityengine;
Using system. collections;
Public class eventtext: monobehaviour {
Void onenabled ()
{
Easybutton. on_buttondown + = downmethod;
}
Void ondisable ()
{
Easybutton. on_buttondown + = downmethod;
}
Void downmethod (string btnname)
{
Print (btnname + "down ");
Debug. logs ("111 ");
}
}
This is a button event.
Then let's talk about how the virtual joystick gets events.
The Code is as follows:
Using unityengine;
Using system. collections;
Public class joystick: monobehaviour {
Public easyjoystick joystick1;
Void Update ()
{
Print (joystick1.joystickaxis );
}
}
Then let's talk about touch.
Using unityengine;
Using system. collections;
Public class easytouchtext: monobehaviour {
Void on_touchstart (gesture g) // trigger events by name
{
Debug. Log ("touchstart" + G. position );
}
}
The above is through listening,
Then, let's write a method for listening to trigger events through scripts.
// Register
Void start ()
{
Easytouch. on_touchstart + = This. on_touchstart;
}
Void on_touchstart (gesture g) // trigger events by name
{
Debug. Log ("touchstart" + G. position );
}
}
Remember, here we need to remove the check mark before broadcast messages.
Then we will write another event, which can be triggered only by clicking a specific location, such as a specific button,
Here we create a cube, and then we create a script to write the following code,
Void on_touchstart (gesture g) // trigger events by name
{
Debug. Log ("touchstart" + G. position );
}
Create a layer in U3D and define it as guicamera.
Set the layer of our cube to guicamera and set easy touch.
This article is from the "computer" blog, please be sure to keep this source http://5152481.blog.51cto.com/5142481/1602259
Learning the easytouch plug-in