Accessing a text variable from another script
I'm trying to access a text variable from my one script to another.
The only reason I don't think this is working is sometimes i am getting this error "cannot implicitly convert type string to unityengine ui text"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class EndScore : MonoBehaviour {
public Text endScore;
public void start()
{
GameObject g = GameObject.Find("PlayerBird");
BirdMovement bmscript = g.GetComponent<BirdMovement>();
bmscript.countText = endScore;
}
}
Comment
The endScore is the Text class, to get the actual text string use:
bmscript.countText = endScore.text;
@filhanteraren I have tried this and it still gives the same error
Why not add a function to your class to pass the string and apply it? Something like,
public ApplyText(string str)
{
theTextObj.text = str;
}
Then you could access it by like saying,
EndScoreRef.gameObject.GetComponent<TheScriptName>().ApplyText("my text");
Have a public reference variable too,
public class EndScore : $$anonymous$$onoBehaviour
{
[Header("SCORE REF")]
public GameObject scoreScriptRef;
start()
{
}
}