Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by tgb777 · Jan 27, 2021 at 10:07 PM · listlistsquest

Hi, I'm trying to make a list based quest manager but I'm struggling to extract certain variables from the list.

I'm trying the make the code switch to the next quest when you reach the required amount of points for each quest. For some reason it's not working and I really can'y work out why.

Any help would be great thanks!

Bit of script I'm trying to make work:

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


And the full script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

 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;
             }
         }
 
 
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CmdrZin · Jan 27, 2021 at 11:13 PM

Something like this should work. I added a 'usedPoints' variable so that quest don't have accumulative points.

     public int currentQuest = 0;
     public int currentPoints = 0;
     public int usedPoints = 0;
     
     public bool IsQuestComplete(int questID)
     {
         bool results = false;
 
         // Assuming that the Quests don't have higher and higher points required.
         if( (currentPoints - usedPoints) >= quests[currentQuest].pointsRequired)
         {
             Debug.Log("Quest " + questID + " completed.");
             usedPoints += quests[currentQuest].pointsRequired;      // use up the points for this quest.
             results = true;           
         }
         return results;
     }
 
     // Call this when the current points change.
     public bool AllQuestsCompleted()
     {
         bool results = false;
 
         if(IsQuestComplete(currentQuest))
         {
             ++currentQuest;         // next quest.
             if(currentQuest >= quests.Length)
             {
                 Debug.Log("All quests completed.");
                 results = true;
             }
         }
         return results;
     }
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

112 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Missing objects upon List.Add(); 1 Answer

How to modify array values? 1 Answer

Best way to list all active quests in a GUI 1 Answer

How to make a simple gui list 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges