EditorGUILayout.Foldout question

Hello everyone,

First of all, bare with me as I am trying to type this from my phone, so excuse any grammatical/typing errors present.

On to the topic at hand:
I am working on an Editor script that makes use of the Foldout function. What I’m trying to achieve is the use of pre-defined Booleans to determine if the Foldout is folded or not.
Something like this:

bool FoldOut(String Text){
     bool Trigger = EditorGUILayout.Foldout(Trigger, Name);
     return Trigger;
}

FoldOut("Text");
FoldOut("Text2");

Instead of this:

bool Trigger = false;
bool Trigger2 = false;

Trigger = EditorGUILayout(Trigger, "Text");
Trigger2 = EditorGUILayout(Trigger2, "Text2")

Obviousley the former method in its current state doesn’t work because with every call, the Trigger bool gets the default value. But I hope you understand what I’m trying to achieve here. Though I have no idea how to myself.

I hope someone can help met with this because I’ve been stuck on this part for some time. And it seems very small, and its solution very obvious… yet I am at a loss.

UPDATE
Another question I’d like to ask is regarding an NPC script I’m working on.
An NPC in my project has its name projected above its head (like in many MMOs), and I’d like to see these changes not only during runtime, but also in the Editor. I’ve looked high and low, but once again I am stumped and unable to find a solution.

This is my Editor script:

// MyScriptEditor.cs
using UnityEditor;

[CustomEditor(typeof(NPC_Script))] 
public class NPC_Editor : Editor {
	bool greetingsUnfolded = false;
	bool choicesUnfolded = false;
		
    public override void OnInspectorGUI() {
		NPC_Script NPC = (NPC_Script) target;
		
		//Edit NPC Name
		NPC.npcName = EditorGUILayout.TextField("NPC Name ", NPC.npcName);

		if(FoldOut("Greetings ")){

		}
    }

	bool FoldOut(string Name){
		bool trigger = false;
		trigger = EditorGUILayout.Foldout(trigger, Name);

		return trigger;
	}
	
	void divLine(){
		EditorGUILayout.LabelField("_________________________________________________________");
	}
}

This is my NPC script:

using UnityEngine;
using System.Collections;

public class NPC_Script : MonoBehaviour {
	//Dialogue box
	bool inDialogue = false;
	float dBoxHeight = Screen.height/15;
	
	Rect dBoxName;
	Rect dBox;
	
	TextMesh npcNameMesh;
	int randomLine;
	
	//Inspector editing
	public string npcName;
	public int greetingAmount;
	public string[] dialogueLines;
	public int choices;
	public string[] choiceLines;
	public string[] responses;
	string currLine;
	
	// Use this for initialization

	void Start () {
		dBoxName = new Rect(32, Screen.height-dBoxHeight-56, 256, 24);
		dBox = new Rect(0, Screen.height-dBoxHeight-32, Screen.width, dBoxHeight);
		
		npcNameMesh = this.GetComponentInChildren(typeof(TextMesh)) as TextMesh;
		npcNameMesh.text = npcName;
	}

	// Update is called once per frame
	void Update () {
		//Make the name always face the main camera
		npcNameMesh.transform.LookAt(Camera.main.transform);
		npcNameMesh.transform.localEulerAngles = new Vector3(0, 
															npcNameMesh.transform.localEulerAngles.y+180, 
															0);
	}
	
	float DistanceTo(GameObject go){
		float xDist = transform.position.x - go.transform.position.x;
		float yDist = transform.position.y - go.transform.position.y;
		float zDist = transform.position.z - go.transform.position.z;
		
		float groundDist = Mathf.Pow(xDist, 2)+Mathf.Pow(zDist, 2);
		groundDist = Mathf.Sqrt(groundDist);
		
		float totalDist = Mathf.Pow(yDist, 2)+Mathf.Pow(groundDist, 2);
		totalDist = Mathf.Sqrt(totalDist);
		
		return totalDist;
	}
	
	void OnGUI(){
		//Display random greeting
		if(DistanceTo(GameObject.FindWithTag("Player")) <= 10.0f){
			if(Input.GetKeyUp(KeyCode.E)){
				inDialogue = true;
				randomLine = Random.Range(0, dialogueLines.Length);
				currLine = dialogueLines[randomLine];

				//Code to make NPC face player <NEED PROPER PLAYER PREFAB>
				//this.transform.rotation = -;
			}
		}else{
			inDialogue = false;
		}
		
		if(inDialogue){
			GUI.TextArea(dBox, currLine);
			GUI.TextArea(dBoxName, npcName);
			
			//Draw le buttons for responses from the player
			for(int i = 0; i < choices; i++){
				if(GUI.Button(new Rect((Screen.width/choices)*i, Screen.height-32, Screen.width/choices, 32), choiceLines[i])){
					currLine = responses[i];
				}
			}
		}
	}
}

It’s all W.I.P. and in need of a lot of cleanup, which is what I’m working on now.

I hope someone can help me with these issues.

Thanks in advance,

Zubaja

I’m just going to shamelessly bump this thread, because I really need help and don’t see the need to flood the forums with new threads.
Sorry if it’s against regulations; this seemed like the wisest of options.