记得初始化
int整数
记得初始化
int整数
变量声明
快速加注释
变量:定义数据
int hp=100;//不能以数字开头,_可用
print(1);//数字
print("23456");//字符串
//只能在定义了MonoBehaviour后使用
Debug.Log(1);//数字
Debug.Log("23456");//字符串
//可以在任何情况下使用
Debug.LogWarning("23456");//提示
Debug.LogError("23456");//错误
//单行注释
/*多行注释*/
换行出*
文件名和类名保持一致。
F2修改文件名。
ctrl+s保存场景,代码。
保存代码后等待更新
VS的脚本创建
代码结构了解
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
enum 名称 {
1,
2,
3,
4.......
}
枚举类型
设置IDE工具:将unity与VS2019相连
c#源文件的创建
int hp = 100;
hp = hp + 10;
hp += 10;
print (hp);
int hp = 100;
hp -= hp-100;// hp = hp-100
print (hp);
debug.LogWaming();输出黄色警告信息
debug.LogError();输出错误
1、public GameObjec xx
2、transform.Find
3、GameObject.Find
4、GameObject.FindWithTag
5、transform.GetChild(0):if(transform.childCount>0)
6、transform.parent
数组
类型[ ] 变量名 = { 变数数据堆 }
1)通过索引查询值 数组名[索引号]
if语句 和 if-else语句
先声明在使用
变量类型 变量名;
变量名 = 变量值;
ctrl +k ctrl+c
变量声明---》变量类型 变量名字 = 变量值
变量名字不能数字
uinty的日志输出
创建的类继承MonoBeHaviour类就可以输print()--只能输出正确
在继承任意类输出
Debug.Log( ) --正常Debug.LogError() --错误
sdasd
ctrl+k ctrl+c(快捷注释)
变量:int+( )=(数字);
print( );
www.cnblogs.com/tonney/archive/2011/03/19/1987577.html