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