EventTrigger triggering 3D object events and Ugui events

Source: Internet
Author: User
Tags bind

The usual event-triggering method in Ugui has been before, and now it's time to talk about another way to trigger events, which not only allows a 2D Ugui trigger but also allows a 3D object to trigger a method.


first write a script to write a log method that triggers the event, as follows:

Using Unityengine;
Using System.Collections;

public class Testtrigger:monobehaviour {

	//initialization
	void Start () {
	
	}
	
	//Update is C Alled once per frame
	void Update () {
       
	} public

    void Clickthis ()
    {
        Debug.Log ("EventTrigger La Ala") ;
    }
}

The next step is to have a UI picture to test this approach. The steps are as follows:


1) First create a new image, then bind the script above and add an event trigger component. as follows:



2) Click on the Add New Event Type button on the Event trigger component to select a method (here Pointerenter the method of detection entry) as follows:




3) This step does the same thing as the normal method of binding an event, drag the picture onto the component and find the Clickthis method in the script above OK. as follows:




last Test: The method is triggered when the mouse enters the area of the white map



------------------------------------------------------------------------------


Here's how the 3D object in the scene starts using the component to trigger the event.


1) Create a new cube in the scene and add a physics Raycaster component to the camera (the object is used to detect mouse rays). as follows:


2) Bind the above script for cube, add event Trigger Select a method (click here to select the method), the steps are the same as the above picture side. Then click Cube in the scene and you can see that the control window pops up the log trigger event.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.