Hi,
What i am trying to do is to setup a controller GameObject which will pass a custom text to other Text object.
I NEED TO HAVE DIFFERENT SCRIPTS ATTACHED TO DIFFERENT TEXT GAMEOBJECT, WHICH I WANT TO AVOID
instead
I WOULD LIKE TO SETUP A WAY IN WHICH THE CONTROLLER SENDS CUSTOM TEXT TO DIFFERENT TEXT GAMEOBJECTS FROM ONE PLACE.
Script one.cs is attached to MessageOne
Script Two.cs is attached to MessageTwo
// TextController
using UnityEngine;
using System.Collections;
public class TextController : MonoBehaviour {
public GameObject textOne;
public GameObject textTwo;
private One one;
private Two two;
// Use this for initialization
void Start () {
one = textOne.GetComponent<One> ();
two = textTwo.GetComponent<Two> ();
}
// Update is called once per frame
void Update () {
one.txt.text = "Sent from Controller to first ";
two.txt.text = "Sent from Controller to second";
}
}
// One
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class One : MonoBehaviour {
public Text txt;
// Use this for initialization
void Start () {
txt = GetComponent<Text> ();
}
// Update is called once per frame
void Update () {
txt.text = "First Message";
}
}
// Two
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Two : MonoBehaviour {
public Text txt;
// Use this for initialization
void Start () {
txt = GetComponent<Text> ();
}
// Update is called once per frame
void Update () {
txt.text = "Second Message";
}
}
How can i use just a single script instead of two ( One.cs, Two.cs ). I have an Idea that i have to make some variable public and attach my script to both TextObjects and assign Them to script itself. and then from Controller Object i have to refer this script.
I have tried several combination of GetComponent, Public, private etc but i can seems to get this thing done right.
Please help guys.