Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
List based quest system

Hi guys I'm trying to build a list based quest system in unity. Everything is working except this bit of code here:

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

I'm not too sure why but any suggestions or help would be great thanks!!

Full script:

public class questManager : MonoBehaviour { public int currentQuestid;

[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;
        }
    }


}`
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Simple typo in for loop:

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

Specifically, you want to decrement i, not increment it.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!