【发布时间】:2016-06-30 15:06:33
【问题描述】:
我有一个简单的问题。
我有两个文件脚本:
-
播放器.cs
using UnityEngine; using System.Collections; using System.Collections.Generic; public class player { public List<item> itemx = new List<item> (); // Here } -
文件 Inventory.cs
using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; public class inventory : MonoBehaviour { public player playerx; itemDatabase database; // Use this for initialization void Start () { database = GameObject.FindGameObjectWithTag ("itemDatabase").GetComponent<itemDatabase> (); //Generate the Slot and Slot Name; for(int i = 1; i <= 24; i++) { playerx.itemx.Add(new item()); // Here playerx.itemx[i] = database.items[i]; // And Here } } }
正如你在 player.cs 文件中看到的,我声明了一个列表变量:
public List<item> itemx = new List<item> (); // Here
在 Inventory.cs 文件中,我想使用以下方法添加值:
playerx.itemx.Add(new item()); And Here
是否可以将 value 变量保存到 player.cs 文件中?
谢谢
【问题讨论】:
-
你需要类的实例。
标签: c# list class unity3d unityscript