Search Unity

How can I make a game where there are 3 quests which each require 3 items to be picked up,

Discussion in 'Scripting' started by JamesW96, Nov 25, 2015.

  1. JamesW96

    JamesW96

    Joined:
    Nov 24, 2015
    Posts:
    3
    I know how to add a collider on to each asset that will be picked up but I dont know how to make so that once the 3 items have been collected, you go on to the next quest to collect 3 more different items.
     
  2. CaoMengde777

    CaoMengde777

    Joined:
    Nov 5, 2013
    Posts:
    813
    you could have something like this

    you have an empty gameObject , or really any gameObject that is always in the game
    and you have it be QuestHandler and you make it handle the quest status

    then you have your objects you collect, with the collision detection
    and when you pick up the item

    you use this to change the variable on the QuestHandler

    Code (CSharp):
    1.  
    2. //Reference script A in script B
    3. private QuestHandler questHandlerScript;
    4.  
    5. //put this line in start()  or awake()
    6. questHandlerScript = GetComponent<QuestHandler>();
    7.  
    8. //change variable in other script
    9. questHandlerScript.itemsCollected++;
    10.  


    and the QuestHandler looks sorta something like this, maybe you want to make it different, this is just a basic idea.

    Code (CSharp):
    1.  
    2. public int itemsCollected = 0;
    3. bool quest00Complete = false;
    4. bool quest01Complete = false;
    5. bool quest02Complete = false;
    6.  
    7. Update
    8. if(itemsCollected == 3)
    9. {
    10.     quest00Complete = true;
    11. }
    12.  
    13. if(itemsCollected == 6)
    14. {
    15.   quest01Complete = true;
    16. }
    17.  
    18. if(itemsCollected == 9)
    19. {
    20.   quest02Complete = true;
    21. }
    22.  

    or

    Code (CSharp):
    1.  
    2. public int itemsCollected = 0;
    3. int questState = 0;
    4.  
    5. Update
    6. if(questState == 0 && itemsCollected == 3)
    7. {
    8.   itemsCollected = 0;
    9.   questState = 1;
    10. }
    11.  
    12. if(questState == 1 && itemsCollected == 3)
    13. {
    14. itemsCollected = 0;
    15. questState = 2;
    16. }
    17.  
    18. if(questState == 2 && itemsCollected == 3)
    19. {
    20. itemsCollected = 0;
    21. questState = 3;
    22. }
     
    Last edited: Nov 25, 2015
    Kiwasi likes this.
  3. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    or just make a Quest where you can fill a list of object to be found.
    you can place a trigger that activates this quest where you want, and call on quest.IsFinished to see if you found all the items.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class Quest : MonoBehaviour
    6. {
    7.     public bool isActive;
    8.     public List<GameObject> itemsToCollect;
    9.     //assuming you have an inventory with a list of items
    10.     public Inventory inventory;
    11.     private bool  isFinished;
    12.  
    13.     public bool IsFinished
    14.     {
    15.         get
    16.         {
    17.             for(int i=0; i<itemsToCollect.items.Count; i++)
    18.             {
    19.                 if(!inventory.items.Contains(itemsToCollect[i]))
    20.                     return false;
    21.                 else
    22.                     return true;
    23.             }
    24.         }
    25.     }
    26. }
     
  4. JamesW96

    JamesW96

    Joined:
    Nov 24, 2015
    Posts:
    3
    I have very little Unity Knowledge as I only started using C# in September so I'm not sure with some of it, It's my first time trying to make a quest system too. would it be possible to make the quest system through an OnTriggerEnter so that when the FPS controller gets within a certain distance, the quest will be activated and once the pickups have been collected, the player will return to activate the next quest,

    I appreciate the help
     
    Last edited: Nov 25, 2015
  5. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
  6. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    just keep a list of all your quests and keep a reference to your current active quest. once that returns IsFinished activate the next in line.