'State' does not contain a definition for 'GetStateStory'

I am receiving a compiler error saying;

"Assets\AdventureGame.cs(19,36): error CS1061: ‘State’ does not contain a definition for ‘GetStateStory’ and no accessible extension method ‘GetStateStory’ accepting a first argument of type ‘State’ could be found "

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

public class AdventureGame : MonoBehaviour
{

    [SerializeField] Text textComponent;
    [SerializeField] State startingState;

    State state;

    // Use this for initialization
    void Start()
    {
        state = startingState;
        textComponent.text = state.GetStateStory();
    }

    // Update is called once per frame
    void Update()
    {

    }
}
1 Like

Hi Shivansh,

Could you copy/paste (and apply code formatting) your State.cs script please.


See also;

Hi, same problem here:
“Assets\AdventureGame.cs(17,36): error CS1061: ‘State’ does not contain a definition for ‘GetStateStory’ and no accessible extension method ‘GetStateStory’ accepting a first argument of type ‘State’ could be found (are you missing a using directive or an assembly reference?)”
Warning: “Assets\AdventureGame.cs(8,27): warning CS0649: Field ‘AdventureGame.textComponent’ is never assigned to, and will always have its default value null”
Warning: “Assets\AdventureGame.cs(9,28): warning CS0649: Field ‘AdventureGame.startingState’ is never assigned to, and will always have its default value null”

This is my state.cs

[CreateAssetMenu(menuName = "State")]
public class State : ScriptableObject
{
    [TextArea(14,10)] [SerializeField] string storyText;

    public string GetStateStory()
    {
        return storyText;
    }
}

And this is my AdventureGame.cs

public class AdventureGame : MonoBehaviour
{
    [SerializeField] Text textComponent;
    [SerializeField] State startingState;

    State state;

    // Start is called before the first frame update
    void Start()
    {
        state = startingState;
        textComponent.text = state.GetStateStory(); 
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

Visual Studio Version 15.9.7 / Unity 2018.3.6f1
Any suggestions? Thanks.

Same problem. Any fix yet?

Cancel that. My error was that I hadn’t saved state.cs.

2 Likes

Privacy & Terms