testBuff.cs
在里面存储一些 自定义的 数据,变量
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class testBuff : MonoBehaviour
{
public string name_;
public int num_;
}
在test.cs中进行使用
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour
{
testBuff[] array;//怎么使用这种自定义变量
void Start ()
{
array = new testBuff[3];
for(int i=0;i< array.Length;i++)//遍历testBuff类型名字为array的变量,并对每一个进行赋值
{
buff = new testBuff;
buff.num_ = i;
}
}
public void test()
{
foreach(testBuff buff in array)
{
Debug.log(" :"buff.num_);//遍历数组,输出 在Start函数中赋值的 变量数据
}
}
}