数组的声明
//----1
int[] hps={20,10,24,5,7};//数组长度为5
//通过索引来访问数据 0 数组名[索引]
int[] hps={};//空数组
//----2
int[] hps=new int[10];//默认初始化0
int[] hps=new int[10]{1,3,5,6,6,7,9,3,57,2};
for循环
通过数组名.Length—确定数组元素个数
方法
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class learn2 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Test();//调用方法
}
//定义方法
void Test()
{
print("Test方法被调用了");
}
// Update is called once per frame
void Update()
{
}
}
枚举类型
enum RoleType{
Mag,soldier,Wizard
}
RoleType rt=RoleType.Mag;
rt=RoleType.Soldier;
方法的参数
void CreateEnemy(Vector3 pos)
{
}
void Start()
{
CreateEnemy(new Vector3(1,1,1));//调用方法
}
方法的返回值
int Add(int a,int b)
{
int res = a + b;
return res;
}
int res = Add(1,1);//调用方法
类的创建申明和构造
class Enemy{
public string name;
int hp;
public void Move(){
Debug.Log(name+"正在移动");}
}//类的定义
Enemy enemy1=new Enemy();//创建对象
enemy1.name="玛丽";
查询UNITY的API手册