unity Inspector属性面板 组件启用与关闭

2018-10-19  本文已影响30人  GB_speak

https://docs.unity3d.com/ScriptReference/GameObject-activeSelf.html
https://docs.unity3d.com/ScriptReference/GameObject.SetActive.html

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CubeApp : MonoBehaviour {

    public BoxCollider box;
    public bool lll = true;
    // Use this for initialization
    void Start () {
        
        AppMain.kaishi += kaishi;
        box = this.gameObject.GetComponent<BoxCollider>();
    }

    public void kaishi(string name)
    {
        this.transform.Rotate(Vector3.up*10);
        if (lll == true)
        {
            box.enabled = true;
            lll = false;
        }
        else
        {
            box.enabled = false;
            lll = true;
        }
        Debug.Log("开始~~~~"+name);
    }
   
    
    // Update is called once per frame
    void Update () {
        
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public delegate void KaiShiEventHandler(string name);

public class AppMain : MonoBehaviour {

   
    public static event KaiShiEventHandler kaishi;
  
    public Button but;

    public int i = 0;
    // Use this for initialization
    void Start ()
    {
        but.onClick.AddListener(OnClick);
    }

    public void OnClick()
    {
        kaishi("ddddddddd~");
    }
    
    // Update is called once per frame
    void Update ()
    {
        
    }
}

上一篇下一篇

猜你喜欢

热点阅读