|
first script need this to be switched out with script bellow, so that it is not gui anymore but is this different text?
(comments are locked)
|
|
so what's the trouble? make a first script also singletone, make there static method to receive new text, and call it whenever you need. if it can't be a singletone, declare public variable of type 'TextMeshExample' in 2nd script public TextMeshExample textMeshExample; assign GameObject with TextMeshExample script attached to GameObject that keeps 2nd script, for it you need save script, go to inspector and drag-n-drop GO with 1st script to GO with 2nd script, exactly to variable 'textMeshExample' we just made. now, add a method to TextMeshExample that will let us set custom text there:
public void SetCustomText(string text)
{
textMesh.text = text;
textMesh.Commit();
}
and the last, call from second script the first one. (in SetDistance method?)
textMeshExample.SetCustomText("my text");
first script - resultusing UnityEngine;
using System.Collections;
public class TextMeshExample : MonoBehaviour
{
tk2dTextMesh textMesh;
int score = 0;
// Use this for initialization
void Start()
{
textMesh = GetComponent();
}
void Coin()
{
score += 1;
textMesh.text = " " +score.ToString();
textMesh.Commit();
}
public void SetCustomText(string text)
{
textMesh.text = text;
textMesh.Commit();
}
}
second script - resultusing UnityEngine;
public class GUIManager : MonoBehaviour
{
public GUIText distanceText;
public TextMeshExample textMeshExample;
private static GUIManager instance;
void Start()
{
instance = this;
textMeshExample.SetCustomText("my text");
}
void Update()
{
GameEventManager.TriggerGameStart();
}
public static void SetDistance(float distance)
{
instance.distanceText.text = distance.ToString("f0");
}
}can you explain in more detail ,sorry i do not understand.
Aug 10 '12 at 10:28 PM
Chris12345
details added 8)
Aug 10 '12 at 11:01 PM
ScroodgeM
were do the codes go and in what scripts?
Aug 10 '12 at 11:13 PM
Chris12345
can i have the 2 scripts put into one script?
Aug 10 '12 at 11:29 PM
Chris12345
Aug 10 '12 at 11:42 PM
ScroodgeM
(comments are locked)
|

I still need all the variables in script 2, i just want a different text on the object.