Unity 3 D学習ノートのC#知識備蓄
1867 ワード
1.listとarrayの違い
2.コンストラクション関数constructor
c++と同様に、マルチステート、継承C#scriptはGameObjectに適用する必要があります.
3.OnEnableとOndisable
それぞれ、ポイントダウン運転とポイントダウン終了時に実行します.
4.Coroutine
5.Time.timeScale
6.static variables and functions
インスタンスを作成する必要はありません.ClassNameを直接使用します.variableName ClassName.FunctionName呼び出し
静的関数に現れる変数は、静的メンバー変数でなければなりません.
7.Enumeration
新しいデータ型を作成することに相当し、データの値は特定のいくつかの値のうちの1つしかありません.
8.data encapsulate
getとsetという特性cとc++にはなく、不思議です.
//list , C++ vector
public List list;
//array , c++
public int[] arr = new int[10];
2.コンストラクション関数constructor
c++と同様に、マルチステート、継承C#scriptはGameObjectに適用する必要があります.
3.OnEnableとOndisable
それぞれ、ポイントダウン運転とポイントダウン終了時に実行します.
//
private void Awake(){
}
private void OnEnable() {
}
void Start() {
}
private void OnDisable() {
}
4.Coroutine
private void Start()
{
StartCoroutine(CallFunction());
}
IEnumerator CallFunction()
{
yield return new WaitForSeconds(2f);
if(playerDied!=null)
{
playerDied();
}
}
5.Time.timeScale
Time.timeScale = 0; //
6.static variables and functions
インスタンスを作成する必要はありません.ClassNameを直接使用します.variableName ClassName.FunctionName呼び出し
public static int power = 0;
public static void PowerInfo()
{
Debug.Log("power is " + power);
}
静的関数に現れる変数は、静的メンバー変数でなければなりません.
7.Enumeration
新しいデータ型を作成することに相当し、データの値は特定のいくつかの値のうちの1つしかありません.
public enum GameState
{
Started,
Ended,
Paused,
MainMenu
}
GameState gameState = GameState.Started;
8.data encapsulate
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;
}
}