Nội dung bài viết ♥
- Các biến (variables)
- Ramdom số trong khoảng
- Hàm Mathf
- Biểu thức điều kiện (Conditions)
I. Các biến (Variables)
- Khai báo biến trong C#
<kiểu dữ liệu> <tên biến> = <giá trị>
- Các kiểu dữ liệu
string nameC = "NameCharacter";
float speed = 2.5f;
double speed2 = 2.5;
bool isDead = true;
II. Random
- Để random 1 số ngẫu nhiên trong khoảng 1-100 ta dùng Random.Range()
void Start()
{
int ran = Random.Range(1, 100);
Debug.Log(ran);
}
III. Mathf
- Mathf.PI
int ran = Random.Range(1, 100);
float sum = ran + Mathf.PI;
Debug.Log(sum);
- Mathf.Abs, Mathf.Acos,...
IV. Điều kiện (Conditions)
- Boolean
bool sky = false;
if(sky) {
Debug.Log("I will go out and play");
}
else {
Debug.Log("I'm staying in bed");
}
- Switch-case
int ran = Random.Range(1, 3);
switch (ran) {
case 1: print("You rolled a 1");
break;
case 2: print("You rolled a 2");
break;
case 3: print("You rolled a 3");
break;
}
0 nhận xét:
Đăng nhận xét
Thank you!