Type `State` is not recognised?

1 Like

1 Like

Hi Siddharth,

The class your have created is called state (first screenshot). In AdventureGame you then try to use it but refer to the type (line 8) as State. C# is case-sensitive, so state and State as class names are not the same.

The solution here is to edit your state.cs script, rename it to State on line 6. You should then also update the state.cs filename to reflect the same change, e.g. rename it to State.cs.

On a related note you have your variable StoryText with a captial “S” as well, its quite important, and will invariably help you in the long run to stick to good naming conventions. Member variables(fields) typically use camelCase, classes and method named use PascalCase. By following these guidelines it will make your code a lot easier to read, example;

using UnityEngine;

public class State : MonoBehaviour
{
    [TextArea(14, 10)] [SerializeField] string storyText;

    public string GetStateStory()
    {
        return storyText;
    }
}

Please note, screenshots for code are not very useful. They tend to be more difficult to read, especially using mobile devices which require the user to constantly scroll back and forth. It also prevents those that offer their time to help you from just copy/pasting a part of your code back to you with a correction/suggestion. Please just copy/paste your code directly into your posts and then apply the code formatting characters both before and after it (see below). Screenshots are useful however for error messages and details from the Unity editor.

Hope this helps :slight_smile:


See also;

1 Like

I’m having a similar issue, but i have copied both the State.cs and AdventureGame.cs text docs from github and it persists (I assumed it was my formatting but apparently not).

The AdventureGame.cs doesn’t seem to recognise that State is a class, and this is fortunately not affecting things too badly atm as all of our variables have been serialised and it seems to just accept them, but it is underlining the States in red and not auto completing properly. Any ideas as to what could be causing this?

Thanks!

What is your version number of Visual Studio Jack?

Currently im on 2018.2.17f1 - not the most up to date version but only a month ish behind - let me update and see if that helps.

Visual Studio, not Unity…

version 15.9.2 - sorry about that

There’s the problem.

There was a bug in this version, it also affected Visual Studio Tools for Unity. It was fixed in version 15.9.3, the current version I believe is 15.9.4.

Look at the top of your Visual Studio window and you’ll see the flag icon for the notifications, you’ll see there’s an update to install. Install it. Close/re-open, the problem should be resolved.


See also;

2 Likes

Yeah - its even fixed the thing where it wasn’t highlighting things like SerializeField properly. Perfect, thanks!

1 Like

You’re welcome.

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

Privacy & Terms