About the button node in the UI in Unity

Source: Internet
Author: User
Tags event listener

The button is the most commonly used UI node and contains components that have

1.Image components

Display the button's texture, drag the image map into the image component, and then click Set Native size to show the map's original size

2.Button components

Interatable: A tick indicates that a button can be clicked and interacted with, and a cancel hook indicates that it cannot be clicked and interacted with.

Transition: Over effect, A. Default state B. Mouse over effect highlighted sprite C. button press effect pressed Sprite D. button disable state disabled sprite

There are four values to choose from, none: Indicates no effect, color tint represents the effect of colour transform implementation, Sprite swap represents the effect of texture transformation, animation represents animation transform implementation effect.

To use the sprite swap type, drag the texture map into the corresponding highlighted sprite,pressed sprite,disabled sprite.

On Click () event Mount:

(1) First write an event script to mount the canvas node above.

(2) The source code of the event script, where On_button_click () is a bit like an event listener.

usingUnityengine;usingSystem.Collections;usingUnityengine.ui; Public classGame_scene:monobehaviour {//Use this for initialization    voidStart () {    }    //when we want to bind the function to the editor's visible. //Public -Modified     Public voidOn_button_click () {Debug.Log ("On_button_click called!!!!"); }    //Update is called once per frame    voidUpdate () {}}

(3) In the button node's on click () property, click "+" to add the event response object as canvas, the response function is On_button_click ().

(4) When you click on the button, the console will output. If you mount a duplicate two event listener, it will output two times.

Property changes:

(1) Change some properties of the button component in your code, such as set to Disabled.

void Start () {        this. Transform. Find ("button"). Getcomponent<button>();         false ;    }

About the button node in the UI in Unity

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.