- Home /
Need workaround for this line of code
Been trying to use/convert an old C# script on youtube tutorial into javascript for use in my project. All was going well until I hit this line of code -
CurrentlySelectedUnit.transform.FindChild("Selected").gameObject.active = false;
CurrentlySelectedUnit = null;
Which gave me this error -
"Assets/Scripts/MousePoint 2.js(24,82): BCW0012: WARNING: 'UnityEngine.GameObject.active' is obsolete. GameObject.active is obsolete. Use GameObject.SetActive(), GameObject.activeSelf or GameObject.activeInHierarchy.
if I use 'GameObject.SetActive' I get this error -
"Assets/Scripts/MousePoint 2.js(24,71): BCE0019: 'GameObject' is not a member of 'UnityEngine.Transform'. "
If I use 'GameObject.activeSelf' I get the same error -
"Assets/Scripts/MousePoint 2.js(24,71): BCE0019: 'GameObject' is not a member of 'UnityEngine.Transform'. "
And if I use 'GameObject.activeInHierarchy' I get the same again.
How can I fix this as the only solutions it gives me, causes more errors ???
use gameObject ins$$anonymous$$d of GameObject ? I don't know the java syntax though so don't trust me.
Answer by Numli · Feb 04, 2015 at 03:48 PM
Maybe like this?
CurrentlySelectedUnit.transform.FindChild("Selected").gameObject.setActive(false);
not tested it though but I think that should work