question

vipulchandu123 avatar image
vipulchandu123 asked

How to rectify this error? can anyone please help me out !

This is my inner function (a bit in my code )

leaderboardPanel.SetActive(false);

for (int i = listingContainer.childCount - 1; i >= 0; i--)

{

Destroy(listingContainer.GetChild(i).gameObject);

}

ErrorCS1061'GameObject' does not contain a definition for 'childCount' and no accessible extension method 'childCount' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)Assembly-CSharpD:\unity projects\New Unity Project\Assets\Scripts 1\PlayFabController.cs231Active H

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

According to the error message, the “listingContainer” seems a “GameObject” object of the Unity Engine, the error message means the “childCount” is not the property of GameObject Class. As far as I know, “transform” has a “childCount” property. If the “listingContainer” is a “GameObject” object, and you want to access the “childCount” of it. you may need to modify the code as something like this.

   for (int i = listingContainer.transform.childCount - 1; i >= 0; i--)
        {
            Destroy(listingContainer.transform.GetChild(i).gameObject);
        }

Besides, this question is a pure question about the Unity native features. The PlayFab technology forum is more focused on solving the technical questions related to the use of PlayFab. If you have more advanced questions about the uses of Unity, please navigate to the Unity forum for professional supports, thanks.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.