[Unity] [C #] Custom Array

 

 

 

 


 

testBuff.cs

Inside some custom data storage, variable

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class testBuff : MonoBehaviour
{
public string name_;
public int num_;
}

Be used in 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函数中赋值的 变量数据
    }
}
}

 


 

Guess you like

Origin blog.csdn.net/BuladeMian/article/details/93359356