Here is a code, based on a state machine, that is simply supposed to read one script that contains a simple integer (health = 1) and display it in the console. However, I can’t get Unity to execute this code, it keeps saying that villagerScript doesn’t exist in the context. I followed the tutorial for GetComponent, but I’m not sure how to fix this.
using UnityEngine;
using Assets.Code.Interfaces;
namespace Assets.Code.States
{
public class PlayStateScene1_1 : IStateBase
{
public class test : MonoBehaviour
{
private Villager villagerScript;
void Awake()
{
villagerScript = GetComponent<Villager> ();
}
}
private StateManager manager;
public PlayStateScene1_1 (StateManager managerRef)
{
manager = managerRef;
if(Application.loadedLevelName != "Scene1")
Application.LoadLevel("Scene1");
}
public void StateUpdate()
{
}
void Start()
{
Debug.Log (villagerScript.health);
}