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

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 ()
    {
        
    }
}

推荐阅读更多精彩内容

  • 原文地址 http://www.fx114.net/qa-75-172454.aspx 使用Profiler工具...
    IongX阅读 3,836评论 1 11
  • host Copyright (c) 2014-2017, racaljk. https://github.com...
    JasonStack阅读 1,418评论 0 4
  • 作为老一代Eclipse玩家,AS也是今年才开始使用,一开始各种不适应,后来发现了keymap有Eclipse的设...
    Mewsoft阅读 260评论 0 0
  • 我愿是沙漠中一颗不起眼的植物! 那样我会拥有坚韧到 即使沙尘爆来袭 也不会改变姿态的决心!
    醒着的猫儿阅读 53评论 0 1