【问题标题】:The name 'i' does not exist in the current context [closed]当前上下文中不存在名称“i”[关闭]
【发布时间】: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当前方法调用。

标签: c# unity3d


【解决方案1】:

问题是这一行

InventoryTest.isfull[i] = false;

你还没有定义“i”。您可能缺少一个 for 循环。

【讨论】:

    猜你喜欢
    • 2015-07-26
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2013-10-02
    • 2014-04-22
    • 2017-06-17
    • 2015-09-11
    • 1970-01-01
    相关资源
    最近更新 更多