Help with Non-Linear Levels
Hello fellow Unity Users! I have a bit of an abstract question - I do have a sketch of the flow, and I''l post that as well. Here goes: I have a "game" that has non-linear levels. Meaning, the level progression isn't 1 - 2 - 3 - 4 - etc. It works like this: Level one is unlocked (we know this is the ONLY level the user can choose and complete). Once level one is complete, it unlocks level 2, 3 and 4. This is where it gets tricky: The User can now choose to complete either 2 or 3 or 4. Once they have completed ANY ONE of those levels, level 5 and 6 become unlocked. Now, there are 2 levels complete (Level 1 + another one) and 4 levels unlocked. The user can now choose any one of the 4 remaining levels. Once they make their choice and complete it, levels 7 and 8 become unlocked. Luckily, my game only has 8 levels, so once levels 7 and 8 become unlocked, it may be easier to keep track of.
Now, in addition to this unlocking of levels, I also want the user to earn a badge for the type of level they have completed. For example, they complete the first level, they earn the Shrink badge. When they complete the next level - if they choose level 4 for example, they'll earn the Fire badge, but if they choose level 2, they would earn the Fall badge.
My Unity project is laid out like this: I have what I call a SCENARIOS scene, this is the scene where my level icons are laid out. Then I have a separate scene for each level. i.e.: a scene for SHRINK (Level 1), one for FIRE (Level 4) etc. there are 8 of these types of Scenes. Each of these scenes are a self-contained game. Then I have a scene called BADGES - this is where the individual badge icons live once they are earned.
So, if you look at the schematic drawing: 1. is the first known level. 2. are the 3 choices that get unlocked after the first level is complete. One of these 3 will be completed, then 3. are the next 2 choice that get unlocked after the one from 2. is complete. this leaves 4 levels to choose from 4. are the next 2 levels to be unlocked, after one of the 4 choices have been completed.
Anyway, I hope that makes sense.
Now, I have been trying to figure this out. LET ME PREFACE: I am NOT a programmer, but Im trying to learn. Please be gentle.
I have tried this:
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
// This is The Highlander -- there can be only one.
// This is a singleton object.
private static GameManager instance = null;
private bool completedShrink = false;
private bool completedSlipFall = false;
private int sceneCount = 0;
void Awake()
{
// Implement the singleton pattern
if (instance == null)
{
// This is the first object
instance = this;
DontDestroyOnLoad(gameObject);
Debug.Log("Game Manager Object Singleton has been set");
}
else if (instance != this)
{
// This is not the first instance
Destroy(gameObject);
Debug.Log("Game Manager Object Imposter destroyed");
}
}
public static GameManager Instance
{
get
{
return GameManager.instance;
}
}
public void CompleteShrink()
{
completedShrink = true;
sceneCount++;
Debug.Log("Shrink scene completed, scene count = " + sceneCount.ToString());
}
public void CompleteSlipFall()
{
completedSlipFall = true;
sceneCount++;
Debug.Log("Slip and Fall Prevention scene completed, scene count = " + sceneCount.ToString());
}
public bool IsShrinkComplete()
{
return completedShrink;
}
public bool IsSlipFallComplete()
{
return completedSlipFall;
}
}
This code only shows 2 scenarios, in the effort to be brief. This code is attached to an Empty Game object called GameManagerObject.
Then I have this:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ScenariosUIManager : MonoBehaviour {
public GameObject ShrinkLocked;
public GameObject ShrinkActive;
public GameObject ShrinkAward;
public GameObject SlipFallLocked;
public GameObject SlipFallActive;
public GameObject SlipFallAward;
public GameObject ProductRotationLocked;
public GameObject ProductRotationActive;
public GameObject ProductRotationAward;
public GameObject FireSafetyLocked;
public GameObject FireSafetyActive;
public GameObject FireSafetyAward;
// Use this for initialization
void Start () {
if (GameManager.Instance.IsShrinkComplete() == true)
{
ShrinkActive.SetActive (false);
ShrinkAward.SetActive (true);
SlipFallActive.SetActive (true);
ProductRotationActive.SetActive (true);
FireSafetyActive.SetActive (true);
}
if (GameManager.Instance.IsSlipFallComplete() || GameManager.Instance.IsProductRotationComplete() || GameManager.Instance.IsFireSafetyComplete())
{
ProShopliftingActive.SetActive (true);
ErgonomicsActive.SetActive (true);
}
if (GameManager.Instance.IsSlipFallComplete())
{
SlipFallActive.SetActive (false);
SlipFallAward.SetActive (true);
}
if (GameManager.Instance.IsProductRotationComplete())
{
ProductRotationActive.SetActive (false);
ProductRotationAward.SetActive (true);
}
if (GameManager.Instance.IsFireSafetyComplete())
{
FireSafetyActive.SetActive (false);
FireSafetyAward.SetActive (true);
}
}
// Update is called once per frame
void Update () {
}
}
This was attached to the UI of the Scenarios scene.
Anyway... needless to say: it does;t work... AND I never even addressed the badges.
I feel like I'm close, but as a non-programmer, I feel like I'm stumbling around in the dark. Or perhaps a better analogy is this: I'm trying to write a book in German, but I don't understand the language, so I'm just typing words on the screen, and hoping they make sentences.
Would anyone care to hold my hand? Respectfully, Kimber
Are you still working with this? Sorry that I never answered this previously. You must have sent it out when email notifications were down.
I am not sure what you are looking for but here is a video of one way you could handle everything.
In the video you will notice two fields, Levels Completed and Badges Awarded. Both of these field work just like the Culling $$anonymous$$ask on a camera. Where you can set the fields to have multiple values. This there is no need for several fields.
Let me know if this is something that you think might work for you.
O$$anonymous$$G! @$$anonymous$$avina This looks like it's exactly what I need to make this work - thank you very kindly for posting that video! The unfortunate part is my lack of knowledge - there was no sound in the video, and when you ran the player window, it was cut off in the video - but I'm not complaining. I appreciate the time you took to make that and post it. I'm going to read about Culling $$anonymous$$asks, and see if I can puzzle out what you've done. Thank you very much for your help! $$anonymous$$.
@$$anonymous$$avina Regretfully, I may need another push... I'm assu$$anonymous$$g that the Scenarios and Badge Icons fields are arrays - I know how to make an array. What I don't know is how to go about adding all the assorted data types: lists, bools and GameObjects to be selectable parts of the array.
I found a couple things, but I'm not sure if I'm moving in the right direction or not. I found an article about making things Serializable [Serialize]. I also found some information about enums. I'm not positive, but it looks like enums may only take numerical data...
Anyway, if you have some time, may I ask that you explain what you've done in your video? I'm very sorry for asking. Thank you.
This is still in the works, yes. I've placed it on the back burner for the time being, while I've been trying to learn more about scripting and thinking about the logic that might be required to pull this off. Thankyou very kindly for providing the video link, I'll watch it in the morning... my brain is just too tired to carry on tonight. I'll let you know if it was helpful. I appreciate you taking the time to reply. Thankyou
Answer by Blue-Cut · Apr 22, 2016 at 10:20 PM
Yeah, what you want sounds super easy to implement for a real programmer (I think I can do this in 1 or 2 hours max). But super hard to handle for a non-programmer.
Because what you needs here it's understanding OOP ^^. You need to have a model that describe what a level is. A level is an object that has :
An id
A state locked/unlocked
A state completed/not completed
A list of level to unlock when completed
A list of badges to give to the user when completed
Then your GameManager has a list of levels. And your UI gets this list of levels from the GameManager and just display them if they have their state unlocked.
I can help you with this if you have the motivation.
@Blue Cut Thank you for taking the time to reply, and I apologize for my delay in getting back to you. I've been reading C# Program$$anonymous$$g for Unity 3D - I'm on Chapter 5, and I do have a basic understanding of the list of items you've described that a level object should have.
Regarding the states locked/unlocked or completed/not completed - could these be booleans? Or are they something else completely.
I would be very interested in your help with this, if you could spare your time. Please remember, I am not extremely skilled in program$$anonymous$$g, so I appreciate a solid explanation of what the code is doing - this helps me to learn to understand the code I'm reading.
If you could $$anonymous$$ch me how to do one set of levels, I'm sure I could take that and apply it to the next set and the next set. If you're still interested, How would you like to do this?
Hi @cre8or I was absent for a while so it's my turn to apologize for the delay. I am not going to study $$anonymous$$avina's answer and all is fine if you are satisfied with it. Anyway about your question on my answer :
Yes, the states locked/unlocked or completed/not completed are absolutly booleans.
When you create a class in C#, you create an "object model". The bullet points I wrote above are nothing more than the properties that a level owns, in the same way that you can represent an article in a shop with a name, a price, a type(food,drink,tool....)
So I would create a level class with these properties
Your level class could also has a "sceneName" propery that represent the scene you want to load when this level is selected. From this point of view, levels are objects that are global to your project and that you make independant from the currently loaded scene.
I think that the most important point to understand in the situation you describe is that there is no "scenarios" in your game, there are just levels that are able to unlock other levels. If you get that, it's a step to be a better coder.
Anyway we are in June now so I don't know if you are still needing help but I am back right know if you have more specific questions or if you want help with the scripts you have write until today. I let you make a sign.