"Lan Unity Development Fundamentals Three" lesson 13 mouse Events

Source: Internet
Author: User

"Lan Unity Development Fundamentals Three" lesson 13 mouse Events

Recommended Video Lecturer Blog: http://11165165.blog.51cto.com/

One, mouse events

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/87/C3/wKiom1fg3pXSskJTAAsFJWZczbE197.png-wh_500x0-wm_3 -wmp_4-s_230421741.png "style=" Float:none "title=" Unity engine Lesson 13 mouse event 205.png "alt=" Wkiom1fg3pxsskjtaasfjwzczbe197.png-wh_50 "/>

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/87/BF/wKioL1fg3p6jfT7bABG8w53gVwA817.png-wh_500x0-wm_3 -wmp_4-s_2124331128.png "style=" Float:none "title=" Unity engine Lesson 13 mouse event 746.png "alt=" Wkiol1fg3p6jft7babg8w53gvwa817.png-wh_50 "/>

Let's take a look at how mouse events are implemented in the scene.

First, we create a Cube,then align the camera with the cubeandthen adjust the viewing angle.

then, we are Create a script Teston the Cube, and then practice the mouse events.

1. Mouse events: OnMouseDown () , OnMouseUp ()

usingUnityengine;
usingSystem.Collections;

Public class Test : Monobehaviour {


    // mouse events

    //1, called when the mouse clicks down
    voidOnMouseDown () {
Print ("Down");

    }
    //2, called when the mouse is canceled
    voidOnMouseUp () {
Print ("Up");

    }


650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/87/BF/wKioL1fg3reiXcCUABG8w53gVwA054.png-wh_500x0-wm_3 -wmp_4-s_2625571747.png "title=" Unity engine Lesson 13 mouse event 746.png "alt=" Wkiol1fg3reixccuabg8w53gvwa054.png-wh_50 "/>

2. Mouse Events: Onmousedrag () , onmouseexit () , onmouseexit () , Onmouseupasbutton ()

usingUnityengine;
usingSystem.Collections;

Public class Test : Monobehaviour {


    // mouse events

    //1, called when the mouse clicks down
    voidOnMouseDown () {
Print ("Down");

    }
    //2, called when the mouse is canceled
    voidOnMouseUp () {
Print ("Up");

    }

    //3, called when the left mouse button is pressed continuously
    voidOnmousedrag () {
Print ("Drag");
    }


    //4, called when the mouse enters the interior
    voidOnmouseenter () {
Print ("Enter");
    }


    //5, called when the mouse is left to the inside
    voidOnmouseexit () {
Print ("Exit");
    }

    //6, when the mouse continues to stay on the object of the game call
    voidOnMouseOver () {
Print ("Over");
        
    }

    //7, when we click on the game object like a button click
    voidOnmouseupasbutton () {
Print ("Upasbutton");
    }

}


"Lan Unity Development Fundamentals Three" lesson 13 mouse Events

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.