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

Hello,

Error I’m having is here:

Full Errors:
Assets\AdventureGame.cs(20,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?)

Assets\State.cs(10,46): warning CS0649: Field ‘State.storyText’ is never assigned to, and will always have its default value null

In unity, when I click on either AdventureGame.cs or State.cs scripts, in the inspector I see a message at the top saying: ''No monobehaviour scripts in the file, or their names do not match the file name."

I’ve already tried to save both scripts and then restarting unity.

State.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = “State”)]

public class State : ScriptableObject
{

[TextArea(14,10)] [SerializeField] string storyText;

public string getStateStory()
{
    return storyText;
}

}

AdventureGame.cs:

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

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()
{
    
}

}

Hey bro, you’ ve created “getStateStory”image but in AdventureGame.cs, you call "GetStateStory ". C# differentiates uppercase and lowercase.

1 Like

Privacy & Terms