How to add logging on what state you are in?

I just had a silly bug where I had missed to change the text after moving on to the next state

AdventureGame.cs
else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            state = nextStates[1];
            textComponent.text = state.getStateStory();

But first I thought it was i mistake in the configuration I had made for a specific state, so I tried to add some logging that point to which state I would need to look in.

Wasn’t able to figure out how to do though. I would like to add a logrow on the file title.

State.cs
    public string getStateStory()
    {
        Debug.Log(state.filetitle);
        return storyText;

Any ideas on how to achieve this?

Hi Viktor,

SerializeObject inherits from Object, which has a name property, so you could use this;

// ...
else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            state = nextStates[1];
            textComponent.text = state.getStateStory();

            Debug.Log("State name is : " + state.name);
// ...

Hope this helps :slight_smile:


See also;

That worked, much appreciated!

1 Like

You’re very welcome :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms