question

Justin Enayat avatar image
Justin Enayat asked

error CS0120: An object reference is required for the non-static field, method, or property 'PlayFabManager.SendLeaderboard(int)'

Assets\Scripts\GameControl.cs(114,9): error CS0120: An object reference is required for the non-static field, method, or property 'PlayFabManager.SendLeaderboard(int)'

Doesn't make sense because neither of them are static.

public void PlayerWin()
    {
        playingUI.SetActive(false);
        winMenu.SetActive(true);
        Cursor.lockState = CursorLockMode.None;
        camAnimator.SetTrigger("RunEnd");
        PlayFabManager.SendLeaderboard(TimerController.timeScore);
    }

It's having a problem with the bottom line starting with "PlayFabManager..." Here is the code its referencing:

public void SendLeaderboard(int time)
    {
        var request = new UpdatePlayerStatisticsRequest
        {
            Statistics = new List<StatisticUpdate>
            {
                new StatisticUpdate
                {
                    StatisticName = (levelName),
                    Value = time
                }
            }
        };
        PlayFabClientAPI.UpdatePlayerStatistics(request, OnLeaderboardUpdate, OnError);
    }

Any help would be much appreciated I have no idea what to do, tried referencing objects and making them static and it just gave more errors.

Player DataLeaderboards and Statisticssupport
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

·
Ivan Cai avatar image
Ivan Cai answered

As your PlayFabManager class inherits from MonoBehaviour, this script needs to be attached to a game object. Then you need to get a reference to the the PlayFabManager component.

PlayFabManager playfabMananger = GameObject.Find("PlayFabManager").GetComponent<PlayFabManager>();

The above will work if your game object is called " PlayFabManager ", swap this for the name of your object if it is called something else.

Then playfabMananger.SendLeaderboard(int); will now work. I find a related thread that can help you.

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.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]