You are never initializing the bask in GameManager.cs
.
public class GameManager : MonoBehaviour {
Basket bask;
public Text text_apple;
// Use this for initialization
void Start () {
bask = GameObject.Find("BaskNameInHierarchy").GetComponent<Basket>()
text_apple.text = bask.displayApple; //i want to call the method of displayApple to get the string returned.
}
}
You can also make the bask public public Basket bask;
. Then drag a GameObject into the inspector on the GameObject that the script is attached to.
Also the Shelf
script should be called Basket
if you’re trying to reach displayApple()
. Or the other way around: private shelf bask
.
2
solved Unable to access variable in other class for text display [Unity]