Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Objective progression

Discussion in 'Scripting' started by DustyShinigami, Aug 9, 2018 at 9:07 PM.

  1. DustyShinigami

    DustyShinigami

    Joined:
    Jan 5, 2018
    Posts:
    56
    I'm trying to figure out how to add objectives to my game and when to trigger the next one when the first has been completed. At the moment I want to see if I can figure it out for myself, but I may eventually have to get additional help soon. For the time being, how would everyone recommend I handle them? I was thinking of doing them with a CoRoutine, but maybe an 'if' statement/bool would be better...?

    Also, though I have a Game Manager, should I add an Empty Game Object to attach the script to to control the different objectives?

    Thanks
     
    Last edited: Aug 9, 2018 at 9:42 PM
  2. Lyker

    Lyker

    Joined:
    Feb 27, 2013
    Posts:
    57
    Maybe you could get some inspiration from an achievement system. Achievements are basically objectives with with a certain progression and conditions applied to them, right? :rolleyes:
     
  3. DustyShinigami

    DustyShinigami

    Joined:
    Jan 5, 2018
    Posts:
    56
    So close and yet... I can't seem to get my objective complete text to pop up. Everything else seems to work so far.

    Code (CSharp):
    1. public class ObjectiveOne : MonoBehaviour
    2. {
    3.     public Text objective;
    4.     public Text checkpointUnlock;
    5.  
    6.     private int required;
    7.  
    8.     void Start()
    9.     {
    10.         required = 0;
    11.         Objective();
    12.         checkpointUnlock.text = "";
    13.     }
    14.  
    15.     void OnTriggerEnter(Collider other)
    16.     {
    17.         if (other.gameObject.CompareTag("Gold"))
    18.         {
    19.             required = required + 1;
    20.             Objective();
    21.         }
    22.     }
    23.  
    24.     void Objective()
    25.     {
    26.         objective.text = "Collect 5 Gold Bars";
    27.         Invoke("Hide", 3f);
    28.  
    29.         if (required >= 5)
    30.         {
    31.             checkpointUnlock.text = "Checkpoint Unlocked";
    32.             Invoke("Hide", 3f);
    33.         }
    34.     }
    35.  
    36.     void Hide()
    37.     {
    38.         objective.enabled = false;
    39.         checkpointUnlock.enabled = false;
    40.     }
    41. }
     
  4. Lyker

    Lyker

    Joined:
    Feb 27, 2013
    Posts:
    57
    In your Hide() method you are disabled certain objects to hide them, I get that, but are you enabling these back again somewhere? Also, you consider using this:

    Code (CSharp):
    1. void Objective()
    2. {
    3.     objective.text = "Collect 5 Gold Bars";
    4.  
    5.     if (required >= 5)
    6.     {
    7.         checkpointUnlock.text = "Checkpoint Unlocked";
    8.     }
    9.    
    10.     Invoke("Hide", 3f);
    11. }
     
  5. DustyShinigami

    DustyShinigami

    Joined:
    Jan 5, 2018
    Posts:
    56
    No. Well, the Checkpoint Unlocked will be after each objective. But the Collect 5 Gold Bars doesn't need to be. I tried what you suggested, but it didn't work. It's weird because I'm trying to incorporate the same method as the Roll a Ball tutorial with the text. I don't get why the second text doesn't work though. Unless I need to link/reference my script for the gold bars...?
     
  6. sunseeker1988

    sunseeker1988

    Joined:
    Jul 10, 2014
    Posts:
    308
    check out the event and delegate system. This video goes over how to implement this for an achievement system and much more.
     
  7. Lyker

    Lyker

    Joined:
    Feb 27, 2013
    Posts:
    57
    If you are ever only disabling the text objects, they are never going to be visible again until you enable them again; is what I'm trying to say. My suggestion was simply a slight, simple and tiny optimization, not bound to your problem in any way.
     
  8. DustyShinigami

    DustyShinigami

    Joined:
    Jan 5, 2018
    Posts:
    56
    Enabling them before any methods begin doesn't work either. I guess I'll have to try linking my game manager script with it.
     
  9. sunseeker1988

    sunseeker1988

    Joined:
    Jul 10, 2014
    Posts:
    308
    This is why im learning about events and delegates\callbacks. I ended up tightly coupling my code. first project, 4 years coding learning all the way. Almost done with my game, but damn will I do stuff different on the next one.
     
  10. DustyShinigami

    DustyShinigami

    Joined:
    Jan 5, 2018
    Posts:
    56
    I'll have to work through that video you've linked :)