Stuck with the first state!

Hi, I’ve been following the videos along quite well however I’ve got to the GetStateStory(); moment and it kicked back the following error
“Assets\AdventureGame.cs(17,36): error CS1955: Non-invocable member ‘State.GetStateStory’ cannot be used like a method.”

I’ve looked at line 17 in my AdventureGame script and I’m not sure what is going on. Any help would be appriciated!
Cheers
Matt

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

This is my State script

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

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

    public string GetStateStory()
    {
        return storyText;
    }
}

Hi Matt,

Welcome to our forum. :slight_smile:

The issue is indeed strange. GetStateStory is a method. For this reason, you should be able to use it like a method.

Please try to restart Unity and VS.

Hi Nina, Thanks for the quick response!
After a restart of unity the state was missing from the StartingState component on my game object.
After dragging my state on to the component it now works!
Thanks
Matt

I’m glad you were able to fix the issue. :slight_smile:


See also:

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

Privacy & Terms