数组:
int[]int_set;//数组对象引用
//创建数组
int_set = new int[10];//堆
//访问数组
int_set[0] = 1;
int_set[1] = 2;
int_set[2] = 3;//数组越界问题
int index=5;
int_set[index] = 10;
//数组的访问
for (int i = 0; i < 10;i++ )
{
Debug.Log(int_set[i]);
}
String :字符串
//创建字符串
string str=string.Format("{0},{1},{2}", "xiaoming",10, "male");
Debug.Log(str);
//判断字符串是否相等
str = "limin";
if(str.Equals("limin")){
Debug.Log("相等");
}
//将所有字母转化为大写
Debug.Log(str.ToUpper());
//将所有字母转化为小写
Debug.Log(str.ToLower());
Static
Static修饰的类的静态方法
classPersion {
int age;
//处理逻辑函数Math.sin,Math.cos
//没有对象实例,就无法访问对象的数据成员和调用成员函数
public sta tic void test() {
Debug.Log("Persion test");
}
public void normal() {
this.age = 0;
}
}
public class game_scene : MonoBehaviour {
void Start (){
Persion.test();
}
}
Static 修饰的静态变量
class Persion{
public static float pi = 3.14f;
}
public class game_scene : MonoBehaviour {
void Start (){
Persion.pi = 3.14f;//不需要实力就可以直接访问
}
Const readonly
Const
//一旦由const定义就无法修改,只能访问
public (static) const int text_const= 3;
//每一个实例,都会有一个readonly变量
//readonly的变量,还有一次修改的机会,
//对象构造的时候构造函数里边
public readonly int test_readonly = 4;
public Person(){
this.test_readonly=5;
}