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.