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