日出⛅
C# 程式碼筆記
日出⛅
Start() 初始化時執行一次
Update() 每一幀執行一次
日出⛅
Awake() 比Start更早執行,建議需要初始化的內容再使用,需要調度的內容使用Start()
日出⛅
public 表公開,任何人都可以讀取或變更
int 整數
string 字串,需用" "框住
float 浮點數,最後必須加上f表示
double 雙精度浮點數,更大的浮點數,消耗空間較大
bool 布林代數
日出⛅
Debug.Log() 輸出除錯信息於Console
print() 同上
日出⛅
// 單行註解   
/*多行註解*/
日出⛅
int.Parse("數字") 字串轉整數
float.Parse("25.36") 字串轉浮點數
XX.ToString("0.00") 數字轉字串,並到小數第二位
日出⛅
XX.Substring( 0, 2 ) 抓取子字串(從第1個字開始連續抓2個)
XX.Split('_') 以_分割字串
日出⛅
條件判斷式寫法
if ( n > 50 ){ }
else if ( n == 10 ){ }
else { }
日出⛅
if ( a ){ } :若a為true
if ( !a ){ }:若a為false
if ( a>5 && b==3 ){ }:AND
if ( a>5 || b==3 ){ }:OR
日出⛅
迴圈寫法
for (int i=0; i<5; i+=1) { print(i); }
int x = 0;
  while (x < 3) {  x+=1 ; print(x);  }
日出⛅
函數宣告
void test(){ } 宣告一個叫test的函數
test() 呼叫test
日出⛅
函數宣告,並有傳值
void test( int a, string b ){ }
test( 7, "hello" )
日出⛅
回傳整數的函數
int test(){ return 123; } //回傳123
int c = test(); //宣告一個變數c儲存回傳值123
日出⛅
宣告類別
public class myCharacter {  public int _hp;  }
myCharacter npc = new myCharacter();
  npc._hp = 90;
載入新的回覆