Is there a way i can make “copies” of a script? What i am trying to do is have a interactable object scipt that has all the esentials for something/someone to “talk.” However, for each different object, i want it to say a different thing. So is there a way i can have a script be put onto object a, and then change it’s script to fit that object, and then put the same script on object b, but change the script to fit what that object needs. For example, i have a person that will change what he will say when a monster is destroyed. So is there a way i can put my script onto that person, and then change it so that it will change when he kills that monster. Then on another object, it will change what it says when it goes a specific distance. Am i making sense? If you need more clarification, just ask.
Heres my code. I use C#…
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 speeches
public bool[] boolList;
public GameObject[] monsterList;
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()
{
ChangeBool();
}
// 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);
}
void ChangeBool()
{
for(int i = 0; i < boolList.Length; i++)
{
if(monsterList[i].active == false)
{
int g = i + 1;
boolList[g] = true;
boolList[i] = false;
}
}
}
}
This is what my code for my interactableobject is. At the bottom are arrays and loops to help switch between the speeches.