Typing Code Into the Inspector - C#

Hi, i have a question. I want to be able to put a specific line of code into a script, but be able to make that code in the inspector. This really sounds confusing. So, in my game, i have different objects taht say different things. However, i want them to change what they say. In order to do this, i have different bools set up for each different thing the object may say. However, to change these bools, i want to change the parameters for each object. For example, i have a person and a sign. I want the person’s “saying” to change when the player kills a monster. I want the sign to change when the player goes to a specific place. However, i dont want to make a different script for each of the objects. I want to change the parameter via the inspector. Heres the code i have so far.

using UnityEngine;
using System.Collections;

public class interactableObject : MonoBehaviour {
	
	public GameObject m_boy;
	public float Dist_from_Object = 3;
	public float yIconOutofScreen = 100000;
	public GameObject interestIcon;
	public Texture2D m_backgroundTexture;
	public string text;
	public int stringNumbers = 3;
	public GUIStyle m_guiStyle;
	public string[] stringList;		//arrays for different speech
	public bool[] boolList;
	
	private Rect textRect;
	private bool IconOn = false;
	private float m_distance;
	private bool textOn = false;
	private bool m_exclaimStart = false;
	private int m_counter;

	


	
	// Use this for initialization
	void Start () 
	{
		interestIcon.gameObject.active = true;
		m_guiStyle.normal.background = m_backgroundTexture;
		textRect.x = Screen.width;
		textRect.y = Screen.height / 10;
		textRect.height = 150;
		textRect.width = 150;
		
		
	}
	
	void Update()
	{
		for (int i = 0; i < stringNumbers; i++)
		{
		}
		
	}
	// Update is called once per frame
	void OnGUI () 
	{
		
		
		m_distance = Vector3.Distance(gameObject.transform.position, m_boy.transform.position);
		
		if(m_distance <= Dist_from_Object)
		{
			if(IconOn == false)
			{
				interestIcon.gameObject.active = true;
				m_exclaimStart = true;
				IconOn = true;

				
				
			}
			
			if(Input.GetButtonDown("Talk"))
			{
				textOn = true;
			}
			
			if(textOn == true)
			{
				StringSay();
			}
			
		}
		
		else
		{
			Vector3 temp_position = interestIcon.transform.position;
			
			temp_position.y -= yIconOutofScreen;
			
			interestIcon.transform.position = temp_position;
		
			interestIcon.gameObject.active = false;
			
			IconOn = false;
			textOn = false;
		}
	
	}
	//ignore this
	public bool ExclaimStart
	{
		get {return m_exclaimStart;}
		set {m_exclaimStart = value;}
	}
	
	//use the public arrays and bools to display a new speech
	//depending on which bool is on
	void StringSay()
	{
		for(int i = 0; i < boolList.Length; i++)
			
		if(boolList[i] == true)
			GUI.Box(textRect, stringList[i], m_guiStyle);
		
	}
	
	// this is want i need help on
	void ChangeBool()
	{
		//have a public object/thing that can be changed in the inspector any way i want
		//this can be literally puting code into the inspector
	}
}

If you need more clarification, just say and i will try to explain better.

You can not put code into the inspector. The only thing you can do is changing values. Do you want to change a bool from your ‘boolList’?
If so, you just need to know which one needs to get which value. E.g.:

boolList[0] = false;

This changes the first bool to false. If that method gets executed, the bool also changes in the inspector.
Hope this helps as I am absolutely unsure if that is what you wanted.

Unityscript has an ‘eval’ command -

eval( “x += 10” );

When that’s run it will expand out to add 10 to x; obviously you can change the string to have it do different things dynamically. So you could have -

var command : String;
var superPowers : int = 0;

function SetCommand( s : String ) { command = s; }
function ExecuteCommand() {
  eval( command );
}

Then set its command to “superPowers++” and you can add superpowers whatever that means.

Keep in mind that eval is extremely slow and shouldn’t be called very often at all.

I don’t know that there is an equivalent for C#, though.

You could also read a file with the speeches you want for each character. I think this is the best choice instead of setting them through the Inspector.

How would you set that up?