Would still like other peoples ideas to enhance my game

Before uploading the game I wanted to humor the idea of maybe adding some enemies and stats on my character.
Would anyone know how to do this?
also how much more complex does it make my game, is it something I that I should try or is it too advanced for me being a beginner.

1 Like

Hey Dominic,

Sounds like a fantastic idea and one that will stretch you a little bit as a developer.

Adding enemies and stats will invariably add some complexity, but you could break this down into smaller pieces of functionality.

For example, rather than having an enemy which actually does something, or you can fight, you could just start with having it appear at a specific point. Or, have it appear at random points. That would be a start.

Regarding player stats, again, instead of thinking health, provisions, strength and so on, you could start with something smaller like how many “steps” (how many options they have chosen, there will be a minimum to win the game) the player has taken, or perhaps the amount of time taken, and then if they are successful in escaping, display this to the screen, on a subsequent go the player may try to complete the game again but taking less steps/time.

The concepts would be similar to other attributes you might add later on, strength, dexterity, wisdom, luck, weapon skill, whatever they may be etc.

I’d also suggest trying some of these features outside of your main game/scene. For example, if you get to a point where you want to introduce some kind of combat, you could do this without the entire “story”, as all your want to develop/test is the interactions between player/enemy and maybe some form of option for “dice rolling” or whatever etc…

My suggestion would be to take your initial thoughts/ideas, then break them down into smaller components which could lead to those ideas, but by developing the smaller ones first you can experiment more easily and take from your experience a series of small wins to help motivate you along the way.

I like your ideas especially the idea of having an enemy show up randomly. How do I know take your ideas and add them. I.E where do I go to see an example/ what variables would I need.
Better yet how do I now take an idea and translate it to be able to search the scripting reference.

I think it would be fair to say you are unlikely to find an exact example in this case.

Start small. At the moment the Text101 game doesn’t have any concept really of a “player”. Perhaps consider creating a Player script and go down the root of the How long did it take the player to escape route, displaying the total time at the end of the game.

Semantically, perhaps the startedAdventure and endedAdventure variables below would be better suited in more of a game manager script than a player script, but as you already have over-lap, e.g. the TextController is effectively running the game, this is really just for example purposes.

Obviously, I don’t want to do it all for you, but something like;

using System;

public class Player 
{
    private DateTime startedAdventure;
    private DateTime endedAdventure;

    public string AdventureTime
    {
        get { return endedAdventure.Subtract(startedAdventure).TotalSeconds.ToString(@"hh\:mm\:ss"); }
    }

    // default constructor
    public Player()
    {
    }
}

In the above, you have a definition for a player, it has two variables of type DateTime, these could store the time at the start and end of the adventure. The Player class also has a public property which calculates the difference between the two times, in seconds, and then returns the value as a string, formatted in hours:minutes:seconds.

You would need to add some functionality to use this.

You’d want a method that can set the time when the player begins the adventure and another to set the time when the adventure has ended. Perhaps;

public void StartAdventure()
{
    // ...
}

public void EndAdventure()
{
    // ...
}

These would get the time now in both cases and set their appropriate variable.

At the moment, as mentioned, your TextController is effectively managing the game. You could create a local variable for the player, and create a new instance of the above class.

As you don’t have any kind of menu as such at the moment to begin the game, you would need to call your StartAdventure method on the Player object perhaps from your first state in TextController, e.g. where they begin.

Then, assuming your adventure is the same as the course one, at the moment at least, when they escape, call the EndAdventure method.

You can then access the AdventureTime property on the Player object to output the total time it took for the player to successfully escape.

The above is untested and kinda just off of my head. Try the above steps and see how far you get, regarding the two methods I mentioned, I’ve deliberately left them blank, see if you can do the bit where you set the two variables with the time now (hint: a Google search for c# time now will lead you in the right direction).

I know this isn’t exactly what you were talking about regarding enemies/combat/stats exactly, but its a starting point that perhaps you could then build on… e.g. add a variable for “health” and perhaps this runs out with each choice the player takes, they may not have enough to make it out unless they “drink the potion” or something like that… display the health string at the top of the scene… another step closer to what you want to do.

1 Like

wow what a nice set of instructions. Thank you so much for the time you put into this.
In addition I am going to try and dissect the instructions you gave me, and see what I can do. If i have any issues I will try and reply to this message again looking for advice.

1 Like

You’re very welcome Dominic, have fun! :slight_smile:

so I added another script called GameController (and added that to the text as well). I then inside TextController named public GameController gametime.
im linking my code to here maybe you can help i am lost I only added what is relevant to the situation in the code

This is the code

Hi Dominic,

You can actually just paste your code into your replies, you can use the code formatting (its really easy) to make it look as it should, see the link at the bottom.

public class GameController : MonoBehaviour {
   
    private DateTime StartedAdventure;
    private DateTime EndedAdventure;
 
    public string AdventureTime
    {
        get { return EndedAdventure.Subtract(StartedAdventure).TotalSeconds.ToString(@"hh\:mm\:ss"); }
    }
    public GameController()
    {
 
    }
    public void StartAdventure()
    {
       
    }
 
    public void EndAdventure()
    {
        print("game has ended");
    }
public class TextController : MonoBehaviour
void Start()
    { myState = States.cottage;
    gametime.StartAdventure(); }
void lantern_2()
    {
        text.text = "I now have a light to help me get through these dark woods, I hope theres no danger in there.\n\n " +
                         " Thank you for playing \n\n  Press space to return to start";
        if (Input.GetKeyDown("space"))
        {myState = States.cottage;
            gametime.EndAdventure();

First question, in your above copy/paste, is this from two scripts, or is this just one script?


See also;

Those are two different scripts. I was trying to show you how i was getting them to communicate.

Phew! That’s a good start then.

Ok, so, have you run into any problems yet?

For example, in the example I gave I deliberately didn’t have the Player class inherit from MonoBehaviour, because you can’t “new” in (instantiate) a class that inherits from MonoBehaviour in the same way.

Also, in your TextController, where you have this;

 gametime.StartAdventure();

within the Start method, what is gameTime? I don’t see it declared in that class as a variable but you may have not included it in the copy/paste, there’s also a missing open brace in the TextController script.

Might be easier to post full scripts up for both to be honest.

public class GameController : MonoBehaviour {
    
    private DateTime StartedAdventure;
    private DateTime EndedAdventure;

    public string AdventureTime
    {
        get { return EndedAdventure.Subtract(StartedAdventure).TotalSeconds.ToString(@"hh\:mm\:ss"); }
    }
    public GameController()
    {

    }
    public void StartAdventure()
    {
     
    }

    public void EndAdventure()
    {
        
    }

}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TextController : MonoBehaviour
{

    public GameController gametime;
    public Text text;
    private enum States { cottage, sink_1, sink_bottle, cabinet_1, door_1, fireplace_1, cottage_poker, fireplace_wall, sink_2, door_2, fireplace_2, cabinet_2,
                          cottage_key, door_3, sink_3, fireplace_3, cabinet_3, Outside, woods_1, lantern_1, shed_1 ,Outside_oil,
                          cottage_oil, fireplace_4, sink_4, cabinet_4, cottage_oil_cartridge, Outside_oil_cartridge,lantern_2};
    private States myState;
    void Start()
    { myState = States.cottage;
        
    }

    void Update()
    {
        print(myState);
        if (myState == States.cottage)
        {cottage();}
        else if (myState == States.sink_1)
        {sink_1();}
        else if (myState == States.sink_bottle)
        { sink_bottle(); }
        else if (myState == States.fireplace_wall)
        {fireplace_wall();}
        else if (myState == States.fireplace_1)
        {fireplace_1();}
        else if (myState == States.cabinet_1)
        {cabinet_1();}
        else if (myState == States.door_1)
        {door_1();}
        else if (myState == States.cottage_poker)
        {cottage_poker();}
        else if (myState == States.sink_2)
        {sink_2();}
        else if (myState == States.fireplace_2)
        {fireplace_2();}
        else if (myState == States.door_2)
        {door_2();}
        else if (myState == States.cabinet_2)
        { cabinet_2();}
        else if (myState == States.cottage_key)
        {cottage_key();}
        else if (myState == States.cabinet_3)
        {cabinet_3();}
        else if (myState == States.fireplace_3)
        {fireplace_3();}
        else if (myState == States.sink_3)
        {sink_3();}
        else if (myState == States.door_3)
        {door_3();}
        else if (myState == States.Outside)
        {outside();}
        else if (myState == States.shed_1)
        {shed_1();}
        else if (myState == States.lantern_1)
        {lantern_1();}
        else if (myState == States.woods_1)
        {woods_1();}
        else if (myState == States.Outside_oil)
        {outside_oil();}
        else if (myState == States.cottage_oil)
        { cottage_oil();}
        else if (myState == States.fireplace_4)
        {fireplace_4();}
        else if (myState == States.sink_4)
        {sink_4();}
        else if (myState == States.cabinet_4)
        {cabinet_4();}
        else if (myState == States.cottage_oil_cartridge)
        {cottage_oil_cartridge();}
        else if (myState == States.Outside_oil_cartridge)
        {outside_oil_cartridge();}
        else if (myState == States.lantern_2)
        {lantern_2();}
    }
    #region State handler methods
    void cottage()
    {
        text.text = "Your eyes blink open, the pain in your left side and the unfimilar surroundings hint " +
                         "that something has happened to you. After a quick look around you notice a fire place, " +
                         " cabinet, sink, and door which you believe leads to the outside. \n\n " +
                         " Press S to View Sink, F to view Fire place, C to View cabinet, D to view Door";
        if (Input.GetKeyDown(KeyCode.S))
        {myState = States.sink_1;}
        if (Input.GetKeyDown(KeyCode.F))
        {myState = States.fireplace_1;}
        if (Input.GetKeyDown(KeyCode.C))
        {myState = States.cabinet_1;}
        if (Input.GetKeyDown(KeyCode.D))
        {myState = States.door_1;}
    }
    void sink_1()
    {
        text.text = "There is a white powder covering the sink, and empty potion bottle that reads sleeper, " +
                         "that explains how I got here  \n\n " +
                         " Press R to Return the cottage, Press B to inspect the bottle";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage;}
        if (Input.GetKeyDown(KeyCode.B))
        { myState = States.sink_bottle; }
    }
    void sink_bottle()
    {
        text.text = "ugh this smells wrong...what is that made out of, \n\n " +
                         " Press R to Return the bottle";
        if (Input.GetKeyDown(KeyCode.R))
        { myState = States.sink_1; }
        
    }
    void fireplace_1()
    {
        text.text = "hhuhh it's cold in here, does'nt look like theres any wood to start a fire either." +
                         " That fire poker looks useful though. \n\n " +
                         " Press R to Return the cottage, Press G to Grab the fire poker";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage;}
        if (Input.GetKeyDown(KeyCode.G))
        {myState = States.cottage_poker;}
    }
    void cabinet_1()
    {
        text.text = "Its locked I wonder if I could find anything useful to help me get out of here.  \n\n " +
                         " Press R to Return the cottage";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage;}
    }
    void door_1()
    {
        text.text = "Its locked. \n\n " +
                         " Press R to Return the cottage";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage;}
    }
    void cottage_poker()
    {
        text.text = "Atleast I found something useful in this place, I bet this is strong enough to pry something open \n\n " +
                     " Press S to View Sink, F to view Fire place, C to View cabinet, D to view Door";
        if (Input.GetKeyDown(KeyCode.S))
        {myState = States.sink_2;}
        if (Input.GetKeyDown(KeyCode.F))
        {myState = States.fireplace_2;}
        if (Input.GetKeyDown(KeyCode.D))
        {myState = States.door_2;}
        if (Input.GetKeyDown(KeyCode.C))
        {myState = States.cabinet_2;}
    }
    void sink_2()
    {
        text.text = "I dont think this will help me that much over here.\n\n " +
                         " Press R to Return the cottage";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage_poker;}
    }
    void fireplace_2()
    {
        text.text = "Theres something writen on the wall I must have missed it before.\n\n " +
                         " Press R to Return the cottage, Press Y to inspect the wall";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage_poker;}
        if (Input.GetKeyDown(KeyCode.Y))
        { myState = States.fireplace_wall; }
    }
    void fireplace_wall()
    {
        text.text = "You must not head into the forest.\n\n " +
                         " Press R to Return the cottage,";
        if (Input.GetKeyDown(KeyCode.R))
        { myState = States.fireplace_2;}
        
    }
        void door_2()
    {
        text.text = "Still locked I dont think im strong enough to pry that open.\n\n " +
                         " Press R to Return the cottage";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage_poker;}
    }
    void cabinet_2()
    {
        text.text = "Lock seems weak enough ... ughhh ...with a quick look inside you notice a key.\n\n " +
                         " Press R to Return the cottage, Press K to take the Key";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage_poker;}
        else if (Input.GetKeyDown(KeyCode.K))
        {myState = States.cottage_key;}
    }
    void cottage_key()
    {
        text.text = "This will unlock that door maybe I should check around one more time before I leave. \n\n " +
                     " Press S to View Sink, F to view Fire place, C to View cabinet, D to view Door";
        if (Input.GetKeyDown(KeyCode.S))
        {myState = States.sink_3;}
        if (Input.GetKeyDown(KeyCode.F))
        {myState = States.fireplace_3;}
        if (Input.GetKeyDown(KeyCode.D))
        {myState = States.door_3;}
        if (Input.GetKeyDown(KeyCode.C))
        {myState = States.cabinet_3;}
    }
    void sink_3()
    {
        text.text = "Those empty bottles probably wont be much use.\n\n " +
                         " Press R to Return the cottage";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage_key;}
    }
    void fireplace_3()
    {
        text.text = "The writing is gone this place somethings wrong about this place.\n\n " +
                         " Press R to Return the cottage";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage_key;}
    }
    void cabinet_3()
    {
        text.text = "I cleared everything out of this before, lets head outside.\n\n " +
                         " Press R to Return the cottage,";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage_key;} 
    }
    void door_3()
    {
        text.text = "Finally can leave this place.\n\n " +
                         " Press R to Return the cottage, Press O to go outside";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage_key;}
        else if (Input.GetKeyDown(KeyCode.O))
        {myState = States.Outside;}
    }
    void outside()
    {
        text.text = "The wind was howling, and the moon was the only light, even though so little actually pierced " + 
                     "the thick brush above. As I strained my eyes to see, I saw a broken lantern laying on a beanch near the house. \n\n " +
                    "Press W to head into the woods, H to look inside the shed, L to inspect the lantern";

        if (Input.GetKeyDown(KeyCode.W))
        {myState = States.woods_1;}
        if (Input.GetKeyDown(KeyCode.H))
        {myState = States.shed_1;}
        if (Input.GetKeyDown(KeyCode.L))
        {myState = States.lantern_1;}
    }
    void woods_1()
    {
        text.text = "It's way to dark over there, I wonder if theres anyway I can get some more light.\n\n " +
                         " Press R to Return the cottage,";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.Outside;}
    }
    void lantern_1()
    {
        text.text = "Seems to be not working looks like I need some oil, and a cartridge.\n\n " +
                         " Press R to Return the cottage,";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.Outside;}
    }
    void shed_1()
    {
        text.text = "Wow, looks like no ones been in here in ages...where am I... I think I spot some oil that might work in the lantern.\n\n " +
                         " Press R to Return the cottage, Press O to take the Oil";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.Outside;}
        else if (Input.GetKeyDown(KeyCode.O))
        {myState = States.Outside_oil;}
    }
    void outside_oil()
    {
        text.text = "I have my oil now I need a cartridge, maybe theres something back in the house. \n\n " +
                    "Press M to return inside the cottage";
        if (Input.GetKeyDown(KeyCode.M))
        {myState = States.cottage_oil;}
    }
    void cottage_oil()
    {
        text.text = "I guess I have to search this place again... \n\n " +
                     " Press S to View Sink, F to view Fire place, C to View cabinet";
        if (Input.GetKeyDown(KeyCode.S))
        {myState = States.sink_4;}
        if (Input.GetKeyDown(KeyCode.F))
        {myState = States.fireplace_4;}
        if (Input.GetKeyDown(KeyCode.C))
        {myState = States.cabinet_4;}
    }
    void fireplace_4()
    {
        text.text = "Doesnt look like anything is here still.\n\n " +
                         " Press R to Return the cottage";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage_oil;}
    }
    void sink_4()
    {
        text.text = "Just the bottles over here.\n\n " +
                         " Press R to Return the cottage";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage_oil;}
    }
    void cabinet_4()
    {
        text.text = "I did notice this before I think it might be the missing cartridge that I need.\n\n " +
                         " Press R to Return the cottage, Press G to take the cartridge";
        if (Input.GetKeyDown(KeyCode.R))
        {myState = States.cottage_oil;}
        else if (Input.GetKeyDown(KeyCode.G))
        {myState = States.cottage_oil_cartridge;}
    }
    void cottage_oil_cartridge()
    {
        text.text = "I have both iteams now lets head back outside.\n\n " +
                         " Press W to walk out the cottage";
        if (Input.GetKeyDown(KeyCode.W))
        {myState = States.Outside_oil_cartridge;}  
    }
    void outside_oil_cartridge()
    {
        text.text = "Lets add these to the lantern.\n\n " +
                         " Press L to walk out the cottage";
        if (Input.GetKeyDown(KeyCode.L))
        {myState = States.lantern_2;}
    }
    void lantern_2()
    {
        text.text = "I now have a light to help me get through these dark woods, I hope theres no danger in there.\n\n " +
                         " Thank you for playing \n\n  Press space to return to start";
        if (Input.GetKeyDown("space"))
        {myState = States.cottage;}
       
    }
    #endregion
}

Hey Dominic,

This was the line I was looking for, or something similar, in order to see how you were accessing the GameController within TextController;

public GameController gametime;

So, have you created a GameObject in the Hierarchy and then attached the GameController script to it, and then dragged it from the Hierarchy into the exposed Game Controller field on the TextController script?

Yes I have done that. My next thought was to try and use GetComponent<>();

1 Like

Great, definitely heading in the right direction here Dominic, you will see these approaches in the upcoming sections also.

You have several choices of setting the reference, either like you already have, or you could find the GameController, these choices will invariably come down to your architecture.

I would suggest for now perhaps not adding both scripts to the same GameObject, whilst you could, and for this simple game that would work and you could use the GetComponent<T> method, it would perhaps then make it less clear what the TextController GameObject actually is/does, is it a TextController to update the screen, or is it a GameController to handle the state of the game? etc.

Privacy & Terms