//list 是变长数组,相当于C++里的vector
public List<int> list;
//array是定长数组,相当于c++的普通数组
public int[] arr = new int[10];
和c++一样,有多态、继承 C# script必须施加在一个GameObject上才能发挥作用
分别在点下运行和点下结束的时候执行。
//执行先后顺序依次是
private void Awake(){
}
private void OnEnable() {
}
void Start() {
}
private void OnDisable() {
}
private void Start()
{
StartCoroutine(CallFunction());
}
IEnumerator CallFunction()
{
yield return new WaitForSeconds(2f);
if(playerDied!=null)
{
playerDied();
}
}
Time.timeScale = 0; //让游戏中一切都停止
不需要创造一个实例才能调用,直接用ClassName.variableName ClassName.FunctionName调用
public static int power = 0;
public static void PowerInfo()
{
Debug.Log("power is " + power);
}
注意静态函数里出现的变量必须是静态成员变量。
相当于创造一个新的数据类型,数据的值只能特定的几个值的其中一个。
public enum GameState
{
Started,
Ended,
Paused,
MainMenu
}
GameState gameState = GameState.Started;
get 和 set 这个特性c和c++里没有,比较神奇。
private float health;
private string playerName;
public float Health
{
get
{
return health;
}
set
{
health = value;
}
}
public string PlayerName{
get{
return playerName;
}
set{
playerName = value;
}
}