Hi Rob, thanks for your response. So I am passing Alpha1 as a string. The reason I’m doing so is that when I tried not casting it to a string it was giving me the red squiggly error line under that value getting passed to the Input.GetButtonDown function:
So I ended up passing it as a string like this:
Here is my code:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AdventureGame : MonoBehaviour {
[SerializeField] Text textComponent;
[SerializeField] State startingState;
//int[] oddNumbers = { 1, 3, 5, 7, 9 };
//string[] daysOfTheWeek = { "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" };
State state;
void Start () {
state = startingState;
textComponent.text = state.GetStateStory();
//Debug.Log(oddNumbers[3]);
//Debug.Log(daysOfTheWeek[4]);
}
// Update is called once per frame
void Update () {
ManageState();
}
private void ManageState()
{
var nextStates = state.GetNextStates();
Debug.Log(nextStates.Length);
if (Input.GetButtonDown(KeyCode.Alpha1.ToString()))
{
Debug.Log(KeyCode.Alpha1.ToString());
}
if (Input.GetButtonDown(KeyCode.Alpha1.ToString()) && (nextStates.Length >= 1))
{
state = nextStates[0];
}
else if (Input.GetButtonDown(KeyCode.Alpha2.ToString()) && (nextStates.Length >= 2))
{
state = nextStates[1];
}
else if (Input.GetButtonDown(KeyCode.Alpha3.ToString()) && (nextStates.Length >= 3))
{
state = nextStates[2];
}
else if (Input.GetButtonDown(KeyCode.Alpha4.ToString()) && (nextStates.Length >= 4))
{
state = nextStates[3];
}
textComponent.text = state.GetStateStory();
}
}