Text object can't be searched for with GameObject.Find

Using Unity 5.1. I am creating a network (multiplayer) instantiated player object that has four cameras the player can choose from (forward, back, left, right). I also have a GUI HUD with a Text object names “Camera Label” for displaying the name of the currently active camera. The problem is getting a reference to Camera Label from the script that controls the camera switching (attached to the player prefab). For instance, if I do the following . . .

Text cameraLabel = GameObject.Find ("Canvas/Camera Label");

. . . I get the following error:

Assets/Scripts/CameraControl.cs(22,25): error CS0029: Cannot implicitly convert type `UnityEngine.GameObject' to `UnityEngine.UI.Text'

Looks like UI objects don’t inherit from GameObject. Any suggestions here? How can I get a reference to a Text object at runtime? (Yes, I know that in normal circumstances, I could make the Text variable public and then link it to Camera Label in the inspector. But remember, this is a network-instantiated prefab, so the link needs to happen in the Start() function. I can’t rely on public variables.)

Thanks for any help.

GameObject.Find returns the object, but you’re trying to get a specific component on that object. Try this:

Text cameraLabel = GameObject.Find("Canvas/Camera Label").GetComponent<Text>();

That error will occur with all components, not just UI.Text. You need to use GetComponent.

Text cameraLabel = GameObject.Find ("Canvas/Camera Label").GetComponent[UnityEngine.UI.Text]();

Replace those square brackets with angle brackets, and it will work fine.

@MrMeows - your solution worked (with angle brackets, of course). Thanks.

(BTW, @OncaLupe and @fafase - I had UnityEngine.UI in my “using” statements, but your suggestion still produced this error: " Assets/Scripts/CameraControl.cs(23,25): error CS0428: Cannot convert method group GetComponent' to non-delegate type UnityEngine.UI.Text’. Consider using parentheses to invoke the method.")