using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
///脚本生命周期=必然事件=消息 Message
///
public class Lifecycle : MonoBehaviour //类名必须与文件名一致,在Unity中重命名时注意
{ //附加到游戏对象的脚本类必须重MonoBehaviour类继承
//public 显示在unity编辑器
//脚本的定义:附加到游戏物体中,定义游戏对象行为指令的代码。
三种高级语言:C# javascript Boo Script
//C#脚本:.cs文件 类文件
//public int a = 100;
//序列化字段,作用:在编译器中显示私有变量
[SerializeField]
private int a;
//希望访问,但不希望出现在编辑器里
//作用:在编译器中隐藏字段
[HideInInspector]
public float b;
//范围
[Range(1, 100)]
public int c;
/*
Unity中代码书写习惯:
c#类:
字段
属性
构造函数
方法
Unity中C#脚本:
字段
方法
*/
//属性(不会在编译器中显示):通常脚本中不写
public int A
{
get { return a; }
set { this.a = value; }
}
//构造函数
public Lifecycle()
{
Debug.Log("constructor");
//不要在脚本中写构造函数
//不能在子线程中访问主线程成员
//b = Time.time;
}
}