Reputation: 926
I want to set my UI text from my script. I can access with public Text but I want to access with private game object.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class WebsiteAd : MonoBehaviour
{
private GameObject name;
void Awake()
{
name = GameObject.Find("/Item0/Name");
}
void Start()
{
name.GetComponent<Text>().text = "My Text";
}
My Hierarchy
Upvotes: 2
Views: 321
Reputation: 20033
GameObject.Find documentation states: "This function only returns active gameobjects."
In order to get access to inactive game objects, you need to use a function which supports them, like GameObject.GetComponentsInChildren.
public Component[] GetComponentsInChildren(Type type, bool includeInactive = false);
Upvotes: 1