Question by
icer19 · Apr 13, 2016 at 11:48 AM ·
nullreferenceexceptiontextmesh
problem accessing textmesh and variable related from other script
//this method reffered in button click
public void text1()
{
GameObject missleNoObject = GameObject.Find ("missleNo_tag");
setTextScript t = missleNoObject.GetComponent<TextMesh> ();
t.text = "1";
}
//Method that i want to access
TextMesh missleNo;
public string text;
// Use this for initialization
void Awake()
{
missleNo = GetComponent<TextMesh>();
}
// Update is called once per frame
void FixedUpdate()
{
setText(text);
}
public void setText(string t)
{
if(text.Length == 1)
{
missleNo.text = t;
}
else if(text.Length == 2)
{
if (missleNo.text.Length >= 2)
return;
missleNo.text = t;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612074740im_/https://answers.unity.com/themes/thub/images/avi.jpg)