首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于列表的quest系统

基于列表的quest系统
EN

Stack Overflow用户
提问于 2021-01-28 05:53:34
回答 1查看 70关注 0票数 1

大家好,我正在尝试在unity中建立一个基于列表的任务系统。除了下面这段代码之外,一切都很正常:

代码语言:javascript
复制
for (int i = currentPoints; i >= 0; i++)
    {
        if (Quests[i].pointsRequired <= currentPoints)
        {
            Debug.Log("ping"); 
            currentQuestid += 1;
        }
    }

我不太确定为什么,但任何建议或帮助都会非常感谢!

完整的脚本:

公共类questManager : MonoBehaviour { public int currentQuestid;

代码语言:javascript
复制
[System.Serializable]
public class Quest
{
    public int pointsRequired;
    public GameObject objects;
    public int questID;
    public string objective;
    public string pointName;
    public string info;
    public float waitTime;
    public bool enabled = false;
    public Text objectiveText;
    public Text remainingText;
    public Text infoText;
}

public Quest[] Quests;
public int currentPoints;
public float currentdelay;
public int required;

void Start()
{
    currentQuestid = 0;
    currentPoints = 0;
    

    for (int i = 0; i < Quests.Length; i++)
    {
        Quests[i].objectiveText.text = Quests[i].objective;
    }
}

void Update()
{
    for (int i = 0; i < Quests.Length; i++)
    {
        Quests[i].objects.SetActive(i == currentQuestid);
    }

    for (int i = 0; i < Quests.Length; i++)
    {
        Quests[i].remainingText.text = Quests[i].pointName + ": " + currentPoints + "/" + Quests[i].pointsRequired;
    }

    for (int i = currentPoints; i >= 0; i++)
    {
        if (Quests[i].pointsRequired <= currentPoints)
        {
            Debug.Log("ping"); 
            currentQuestid += 1;
        }
    }


}`
EN

回答 1

Stack Overflow用户

发布于 2021-01-28 05:57:59

for循环中的简单拼写错误:

代码语言:javascript
复制
for (int i = currentPoints; i >= 0; --i)
{
    //Be safe
    if (Quests.Length <= i)
        continue;
    if (Quests[i].pointsRequired <= currentPoints)
    {
        Debug.Log("ping"); 
        currentQuestid += 1;
    }
}

具体地说,您希望递减i,而不是递增它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65927962

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档