A case of 4.unity3d presets

Source: Internet
Author: User

Using Unityengine;
Using System.Collections;
Using System.Collections.Generic;
Using Unityengine.events;
Using Unityengine.ui;

public class Testclick:monobehaviour {

public static gameobject my;
Use this for initialization
void Start () {

1. To find this button when the program is opened create a new button if not found
Gameobject btnobj = Gameobject.find ("Buttonx");
if (btnobj = = null) {//if BTN not
my = Gameobject.find ("New Prefab"); Find the preset for this button
Gameobject can = Gameobject.find ("Canvas"); Find Canvas
Gameobject go = Instantiate (my, new Vector3 (260, -70, 0), quaternion.identity); Create a new preset in position 260,-70
Go.name = "Buttonx"; Name of the instance name
Go.transform.SetParent (Can.transform, false); Add this preset to the canvas.
Debug.Log ("create!");
}
}
public void Click () {
Debug.Log ("button 134 Clicked. Testclick. ");
Gameobject btnobj = Gameobject.find ("Buttonx");

Button btn = btnobj.getcomponent<button> ();

Btn.interactable = false;
Here's how to delete this button,
Gameobject.destroy (Btnobj);
btn.enabled = false;
Gameobject txtobj = Gameobject.find ("Textx");
Text txt = txtobj.getcomponent<text> ();
txt.text= "Xiajing 12345";
Application.Quit ();

}
public void Click2 () {
Gameobject btnobj = Gameobject.find ("Buttonx");
if (btnobj = = null) {
Gameobject.instantiate (my,new Vector3 (10,10,0), quaternion.identity);
Gameobject can = Gameobject.find ("Canvas");
This code is added to the can, but it doesn't show
Gameobject Buttonadd = new Gameobject ("Buttonadd");
Buttonadd. AddComponent <Button> ();
Buttonadd.transform.parent = Can.transform;

//
my = Gameobject.find ("New Prefab");
Debug.Log ("ABC:" +my. GetType (). ToString ());
My.
Gameobject Buttonprefab = new Gameobject ("Buttonprefab"); This is the name of the object.
Text TX =buttonprefab.addcomponent <Text> ();
Tx.font = new Font ("Arial");
Tx.fontstyle = Fontstyle.normal;
tx.text= "Add";
ButtonPrefab.transform.SetParent (Can.transform,false);


Gameobject go = Instantiate (my, new Vector3 (260, -70, 0), quaternion.identity);
Go.name = "Buttonx";
Debug.Log (Go.name);
Go.transform.SetParent (Can.transform,false);
I don't know what that means.
Gameobject cube = gameobject.createprimitive (Primitivetype.cube);
Cube. Addcomponent<rigidbody> ();
Debug.Log ("Btnobj is null");
} else {

}
}
Update is called once per frame
void Update () {

}
}

A case of 4.unity3d presets

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.