【发布时间】:2020-04-16 02:57:47
【问题描述】:
我正在统一制作清单,并且我有一个脚本的一部分,当它为空时,它会使插槽未满,但我只是收到此错误消息。 这是我的第一个脚本(错误在此)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Slot : MonoBehaviour
{
private InventoryTest InventoryTest;
public void DropItem ()
{
foreach (Transform child in transform)
{
child.GetComponent<Spawn>().SpawnDroppedItem();
GameObject.Destroy(child.gameObject);
}
}
// Start is called before the first frame update
void Start()
{
InventoryTest = GameObject.FindGameObjectWithTag("Player").GetComponent<InventoryTest>();
}
// Update is called once per frame
void Update()
{
if (transform.childCount <= 0) {
InventoryTest.isfull[i] = false;
}
}
}
这是我的第二个脚本(这只是让 isfull 和东西
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InventoryTest : MonoBehaviour
{
public bool[] isfull;
public GameObject[] slots;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
【问题讨论】:
-
在第一个Update函数中:
InventoryTest.isfull[i] = false;'i'未定义。 -
没有人尝试读取异常消息 :( "名称 'i' 在当前上下文中不存在" 意味着在上下文中没有
i当前方法调用。