So i changed the code for the loop but the loop broke my game and nothing works.
also i think i followed the code correctly but i get 2 errors
First Error
NullReferenceException: Object reference not set to an instance of an object
AdventureGame.ManageStates () (at Assets/Scripts/AdventureGame.cs:28)
AdventureGame.Update () (at Assets/Scripts/AdventureGame.cs:23)
Second error
NullReferenceException: Object reference not set to an instance of an object
AdventureGame.Start () (at Assets/Scripts/AdventureGame.cs:18)
here is my code
AdventerGame.cs
`using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AdventureGame : MonoBehaviour {
[SerializeField] Text textComponet;
[SerializeField] State startingState;
State state;
// Use this for initialization
void Start () {
state = startingState;
textComponet.text = state.GetStoryState();
}
// Update is called once per frame
void Update () {
ManageStates();
}
private void ManageStates()
{
var nextStates = state.GetNextStates();
for (int index = 0; index < nextStates.Length; index++)
{
if (Input.GetKeyDown(KeyCode.Alpha1 + index))
{
state = nextStates[index];
}
}
}
}
and the states.cs script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "State")]
public class State : ScriptableObject
{
[TextArea(10, 14)]
[SerializeField] string storyText;
[SerializeField] State[] nextStates;
public string GetStoryState()
{
return storyText;
}
public State[] GetNextStates()
{
return nextStates;
}
}