Unity UI C # programming app UI interface switching

Source: Internet
Author: User

One, the search for the component under the Canvas, button, text;

1, defining the component name

public class Infornew:monobehaviour {
Public Button _homel, _menu, _jia, _jian;
Public Text _caidan, _fenshu;
public int _adds;
Public Gameobject _camera;
Public Gameobject _list;
Public Gameobject _destroy;

2, find the component under the Star method
void Start ()
{//Find the component under itself (the path to the component). Find his generic type < type name > (): This method returns a generic type.

Formula: This.transform.fan ("path under its own location, without its own position"). Type of getcomponent< components > ();
_homel = This.transform.Find ("Panel_tu/panel_top/button_home"). Getcomponent <button > ();
_menu = This.transform.Find ("Panel_tu/panel_bottom/panel_0/button_menu"). Getcomponent<button > ();
_jia = This.transform.Find ("Panel_tu/panel_bottom/panel_1/panel_2/button_jia"). Getcomponent<button > ();
_jian =this.transform.find ("Panel_tu/panel_bottom/panel_1/panel_2/button_jian"). Getcomponent<button > ();
_fenshu =this.transform.find ("Panel_tu/panel_bottom/panel_1/panel_2/textv"). Getcomponent<text > ();//Text type

To add a button event

This represents itself as if there are multiple buttons that can be directly defined by the name. Getcomponent<button> (). Onclick.addlistener (ONCLICKBTN);

Onclick.addlistener (); Add event (the method name of the event);

Formula: this. Getcomponent<button> (). Onclick.addlistener (onclickbut);

_homel.onclick.addlistener (onclickbut); _menu.onclick.addlistener (Onclickmut); _jia.onclick.addlistener (onclickads);

_jian.onclick.addlistener (Onclickjian);
The text initialization assignment under this component.
_fenshu.text= "0";
}
public void onclickbut()// method of event
{
Instantiate (_camera);//Create an Object
Destroy (_destroy);//Destroy his own

}//ui switching over the same session
public void Onclickmut ()
{
Instantiate (_list);
Destroy (_destroy);
}
void Onclickads ()
{
if (_adds<9)
{
_adds++;
_fenshu.text = _adds. ToString ();
}
}
void Onclickjian ()
{
if (_adds>0)
{
_adds--;
_fenshu.text = _adds. ToString ();
}
}

}

Unity UI C # programming app UI interface switching

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.