sharing functions between a game object and a scriptable object,Functions between a scriptable object and game objects
So I've got a scriptable object and a game object, the game object needs to access the function on the scriptable object. I'm really new to unity and have attempted it in the code below. However, I get an error telling me:
An object reference is required for the non-static field, method, or property 'State.GetStateStory()'
Here's my code:
scriptable object:
public class State : ScriptableObject
{
[TextArea(14, 10)] [SerializeField] string storyText;
public string GetStateStory()
{
return storyText;
}
}
Game Object:
public class AdventureGame : MonoBehaviour {
[SerializeField] Text textCompoment;
[SerializeField] state startingState;
State currentState;
// Use this for initialization
void Start () {
currentState = startingState;
textCompoment.text = State.GetStateStory();
}
...
Starting State will (when it functions) contain for displayed text in a UI text box.
I appreciate any help you can give me.
In your adventuregame script use currentstate.GetStateStory instead of State.GetStateStory
Your answer

Follow this Question
Related Questions
Simple Question 2 Answers
Load Scene Unity by Application.LoadLevelAsync 0 Answers
Problem about finding script name 1 Answer
Calling a function from another script 0 Answers
List.FindIndex 1 Answer