40046人加入学习
(83人评价)
Unity中的C#编程 - 零基础(Unity 2017)

完成于2017-11-06

价格 免费

数组和声明使用:

//数组    类型[ ]  数据名 = {数组值}

int[ ]hps={100,20,80,90,30};//数组长度为5

//通过索引来访问数据  ,从0号开始,通过数组名[索引],∵数组长度为5,0,1,2,3,4,∴数组的最大索引为4

//如果想索引第二个数据,即20→hps[1]

 

[展开全文]

if语句

if(hp<=0)

{print("播放死亡动画");}

else

{print("播放行走动画");}

[展开全文]
YUANo · 2023-07-31 · 113-if语句 0

比较运算符:

int hp=100; //血量100

bool  res=hp>0;//当血量>0时

print(res);//输出res

补充内容:

int hp=100;

hp+=10 ;  //hp=hp+10;

print(hp);

//hp=100;

//hp=hp+10是hp=100所以hp+10,就是hp为110

//输出hp110

hp-=100;  //hp=hp-100

print(hp);

//hp为110,hp-100,所以输出的值为10

[展开全文]

加减乘除的数据运算:

int a=90;int b=10;

int res=a+b;

print(res);

int res1=a-b;

int res2=a*b;

int res3=a/b;

print(res1);

print(res2);

print(res3);

对于除法来说,/,如果相除之后是小数,不符合int变量类型,所以两个整数相除,小数部分会被自动舍去

3+3.2f; 

//一个整数类型跟浮点类型相加的时候,float类型比整数类型大的时候,定义为float类型

float res4=3+3.2f;

∴多个数据类型运算,返回结果类型是数据类型大的

字符串:string str1="my name is"

string str2="siki"

string strRes=str1+str2;

print(atrRes);

 

[展开全文]

3.bool类型

bool来表示true或false

bool isDie=false;

4.字符串类型:

string name="绝地战士”;

//用英文双引号括起来的字符

[展开全文]

数据类型:

1.整数类型:

一般整数类型选int类型,范围不会超过这个

如果血量不超过100,处于节约内存方面的考虑,可以使用sbyte变量

如果是-30000~30000,可以用short变量

总体来说变量根据需要选择

2.浮点类型

浮点类型有两种double  float

float hp2=3.4f;

//小数后面跟f是为了证明是float 类型,否则就默认为double类型,这样前后类型不一致,系统没办法操作

 

[展开全文]

2.先声明变量再赋值

int hp;

hp=100;//得初始化一下变量,不然输出报错

print(hp);

int类型是整数类型

[展开全文]

变量:

如定义一个血量:

int hp=100;

int变量类型+hp变量名称=变量的值

“=”是赋值

这样print(hp)就能输出100,

 

[展开全文]

输出日志:

1.print:输出正常的日志

:把Log分成了三类

2.Debug.Log

Debug.LogWarning:在输出时同时给警示

Debug.LogError:在输出时给错误提示

 

[展开全文]

多行注释:/*作为注释开头,*/作为注释结尾

[展开全文]

类里面

class Enemy()

{

    public string name;

    public int hp;

}

访问:

Enemy enemy1 = new Enemy();

 

[展开全文]

/定义方法 void Test(){
print("Test方法被调用了");
0
void CreateEnemy() {
print("创建敌人");
print("设置敌人位置");
print("设置敌人的初始属性");

[展开全文]

//for循环
//print("创建了一个敌人");
//for(int i = 1; i <= 10; i++){
// /1 循环体 
// print("创建了一个敌人"+i); 
//}
//for(int i = 1; i <= 100; i++){
// print("创建敌人"); 
/1}
//for(int i = @;i<10;i++){
// print("创建敌人”); 

[展开全文]

//for循环
//print("创建了一个敌人");
//for(int i = 1; i <= 10; i++){
// /1 循环体 
// print("创建了一个敌人"+i); 
//}
//for(int i = 1; i <= 100; i++){
// print("创建敌人"); 
/1}
//for(int i = @;i<10;i++){
// print("创建敌人”); 
11}

[展开全文]
街酒 · 2023-03-16 · 116-for循环 0

int[] hps = new int[5]{34,2,324,3,2};

[展开全文]

int[] hps = {100,20,80,90,30};//长度为5

//通过索引值来访问数据 数组名【索引值】

print(hps[1]);//20

print(hps[4]);//30

[展开全文]

int hp = 90;

if(hp<=0)

{

         print("播放死亡动画");

}

else

{

       print("播放行走动画");

}

[展开全文]
街酒 · 2023-03-16 · 113-if语句 0

//比较运算符

//> < <= >= == !=

//int hp = 100;

//boll res = hp>0;

//print(res);

int hp = 100;

//hp = hp +10;

//hp += 10;

//print(hp);

//hp -=100;//hp = hp-100;

//print(hp);

[展开全文]

授课教师

问问题加入A计划,有专门负责答疑的老师哦!!!

课程特色

下载资料(2)
视频(37)