fps game js code Unity 4.6.7 to 5.1.2f1

when i try use this code unity 5.1 : healthtext.guiText.text =“health :” + health;

I’m getting this error but it working on unity 4.6.7
BCE0144: ‘UnityEngine.Component.guiText’ is obsolete. Property guiText has been deprecated. Use GetComponent() instead. (UnityUpgradable)

i tried like this but its not working. anyone get help?

healthtext.GetComponent(“health :”) + health;

healthtext.GetComponent<GUIText>().text = "health :" + health;
healthtext.GetComponent("GUIText").text = "health :" + health;

hope the second (JS code) is correct syntax

thanks for your attention (i tried for js)

BCE0019: ‘text’ is not a member of ‘UnityEngine.Component’.

if you pass a string into getcomponent it doesn’t know the type, so it returns a generic “component” type and you then need to cast it. Much better to not use the string parameter and go with the typed version.

also, although it’s not listed I think unityscript supports

GetComponent.<Type>()

(note the “.”)

still I couldn’t do it. :confused: