Game state not responding in inspector

I am currently having trouble with game state, being level and crrentScreen. I have the code written out but it doesn’t update in the debug inspector. level remains at 0 and currentScreen at MainMenu, user input has no effect on these.

public class Hacker : MonoBehaviour
{
//Game state
int level;

enum Screen { MainMenu, Password, Win };
Screen currentScreen = Screen.MainMenu;

void Start() //Use this for initialization.
{
    ShowMainMenu();
}
void ShowMainMenu()
 {
     Terminal.ClearScreen();
     Terminal.WriteLine("What would you like to hack into?");
     Terminal.WriteLine("Press 1 for the local library");
     Terminal.WriteLine("Press 2 for the police station");
     Terminal.WriteLine("Press 3 for the military base");
     Terminal.WriteLine("Enter your selection: ");
 }

void OnUserInput(string input)
{
    Terminal.ClearScreen();

    if (input == "1")
    {
        level = 1;
        StartGame();
    }
    else if (input == "2")
    {
        level = 2;
        StartGame();
    }
    else if (input == "Xendalta")
    {
        Terminal.WriteLine("An honor, lord arbiter!");
    }
    else if (input == "menu")
    {
        ShowMainMenu();
    }
    else 
    {
        Terminal.WriteLine("Please enter a valid level.");
    }

}

void StartGame()
{
    currentScreen = Screen.Password;
    Terminal.WriteLine("You have chosen level " + level);
}

}

Please inform me if and where I went wrong in this.

void OnUserInput(string input)
{
Terminal.ClearScreen(); // Remove this line. It is clearing your screen on user input.

Yes, that was intentional, the only problem I’m having is that the “level” remains at zero even after selecting level 1. The same applies for “Current Screen” enum, remaining on “MainMenu” when it should be set to “Password” displayed in the debug inspector on input 1 or 2.

How many Hacker scripts are there in your scene? Which version of Unity do you use?

Version 2018.3.11f1. I have just one script.

Add Debug.Logs or prints to your code to narrow down the problem a bit further. For example:

void OnUserInput(string input)
{
    Debug.Log("input: " + input);
    Terminal.ClearScreen();

    if (input == "1")
    {
        level = 1;
        Debug.Log("level was set to " + level);
        StartGame();
    }

    // code
}

Play your game. What does your console in Unity say?

Hi Reed,

Just a suggestion,
I have read many posts related to a similar issue as yours and some of them were having the issue because they had the WM2000 prefab selected instead of the gameobject in the hierarchy. Due to this, they were unable to see any updates in the inspector. Maybe perhaps, you are having the same issue?

Cheers!

Thanks, but I have checked into that prior to my inquiry and doesn’t appear to be a selection of the wrong prefab as suggested. And the console does respond as ordered, however the issue is in the prefab’s debug inspector. Where public as well as other hidden variables are displayed. In the video tutorial these displays were labeled “level” and “Current Screen” and would change instantly for the tutor upon user input for level selection. That is my only issue is the the inspector will not update, and as far as I can tell, my code is the same as the instructor’s with the only exception being the Easter egg.

Hi Reed,

Sorry my suggestion didn’t help. :sweat_smile:

You said the issue is in the ‘prefab’s’ debug inspector. Can you clarify that when you say prefab, you mean the WM2000 gameobject in your game hierarchy & not the WM2000 prefab in your assets under your project tab? This has me confused a bit and clearing this up might help me with debugging your issue.

Cheers! :slight_smile:


Yash_Agrawal

    August 8

Hi Reed,

Sorry my suggestion didn’t help. :sweat_smile:

Reed_Ridyolph:
however the issue is in the prefab’s debug inspector

You said the issue is in the ‘prefab’s’ debug inspector. Can you clarify that when you say prefab, you mean the WM2000 gameobject in your game hierarchy & not the WM2000 prefab in your assets under your project tab? This has me confused a bit and clearing this up might help me with debugging your issue.

Cheers! :slight_smile:


Visit Topic or reply to this email to respond.

To unsubscribe from these emails, click here.

ScreenCaptureProject11.mp4 (3.59 MB)

Could you please upload the video properly to the forum and format your answer properly?

The forum will support a file size of up to 10MB, if your video is larger than this you could consider uploading to YouTube and then embedding the video into your post.


See also:

The forum does not support the file type and I’m not going to upload it to youtube when it is being checked by one person. I’ve described the issue as well as I could and this was the only way to demonstrate the issue. If your unable to help than I apologize for even bothering in the first place. Good day to you.

I found the issue, but thanks anyway for trying.

Hi Reed,

Glad you solved your issue. Can you tell how you resolved it?
Someone else might have the same issue in the future & this post will help them out if the situation arises.

Cheers!

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

Privacy & Terms