Unity_API之monoBehaviour

monobehaviour是unity脚本中最常见到的类之一,所有创建的脚本都是默认继承于它。
根据unity官方文档,monobehaviour继承于behaviour  ,而behaviour 的描述是*Behaviours are Components that can be enabled or disabled。*这里说明自己创建的脚本就是和其他组件一样。
它有一个 属性叫 *runInEditMode*  意思是在编辑状态下调用,就是可以在脚本未激活状态下调用,估计是做一些初始化的事情(我还没有去试过:)。
它有一大票的*message*用于各种游戏常用事件相应![message的一部分](https://img-blog.csdn.net/20170617234614953?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvWlhLX0NVSVQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)

他们可以被重构(我还没有去试过:)。
它有一些比较重要的继承的成员

  1. enabled
         Enabled Behaviours are Updated, disabled Behaviours are not
     2. isActiveAndEnabled
         Has the Behaviour had enabled called.
     3. gameObject
    The game object this component is attached to. A component is always attached to a game object
    4.tag
    The tag of this game object.
    5.transform
    The Transform attached to this GameObject.
    6.name
    The name of the object
    实例如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class API_10MonoBehaviour : MonoBehaviour {

    public Cube_manage go;
    // Use this for initialization
    void Start () {
        Debug.Log(this.isActiveAndEnabled);
        Debug.Log(this.enabled);
        enabled = false;
        Debug.Log(this.gameObject);
        Debug.Log(this.name);
        Debug.Log(this.tag);
        Debug.Log(this.transform);

        print("haha");

        Debug.Log(go.isActiveAndEnabled);
        Debug.Log(go.enabled);
        enabled = false;
        Debug.Log(go.gameObject);
        Debug.Log(go.name);
        Debug.Log(go.tag);
        Debug.Log(go.transform);
    }

    // Update is called once per frame


    void Update () {

    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值