Having trouble with GetComponent

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);
			
	}

villagerScript is declared in the scope of your nested type test. Therefore only test can access it.

    public class test : MonoBehaviour
    {
       private Villager villagerScript;
 
       void Awake()
       {
         villagerScript = GetComponent<Villager> ();
       }
    }

If you move it’s declaration out to PlayStateScene1_1 you will have access to it from both PlayStateScene1_1 and test.