I keep getting an error on nextStates on VS, sayinh that “Cannot Apply Indexing to an expression of type object”. I have the same code as in your examples. How can i fix this?
using System;
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()
{
ManageState();
}
private void ManageState()
{
var nextStates = state.GetNextStates();
if (Input.GetKeyDown(KeyCode.Alpha1))
{
state = nextStates[0];
}
}
What does GetNextStates() return? Make sure it returns an array of States, not just a single State object, since otherwise you won’t be able to access elements of it.
I am a total noob, and have no idea. what is wrong. everything that you see in the code is what I saw in the tutorial. I will try from scratch this lesson, to see what I can do. But I would like to understand what the error log means.
So the solution was, that when I was typing GetnextStates, in VS, there where 2 options one that defined it as OBject, and one thta defined as a State, i was using the one as Object by mistake.