[RESOLVED]How can I remove button permanently once it has been pressed on Android/iOS? Player pr..

Hi!

I am very much a beginner but I have pieced together this script which works great to remove the “Rate this game” button… But I would like it to remove it permanently once pressed so I think I need to make use of player prefs if I am not mistaken?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RateGame : MonoBehaviour
{

    public GameObject RateButton;

    public void OpenURL()
    {
        Application.OpenURL("http://google.com/");
        Debug.Log("is this working?");
        RateButton.SetActive(false);
       
    }
}

But I don’t really understand how to do that… I have used player prefs for an integer before but this is different.

Can anyone point me in the right direction please?

Thanks!

@Dommo1

Check the PlayerPrefs docs:

You can only store value types it supports.

So you could store rateThisGameDone = 1 to let your game later know it is rated.

If the value is 0 or doesn’t exist, then you will show the rate button.

And you can check if value exist:

And you can set the value like this:

You can get the value like this:

Thanks! I think I am getting closer… But may be hideously off ha! And I can’t work out how to implement HasKey. This is what I have now:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RateGame : MonoBehaviour
{

    public GameObject RateButton;
    public int ButtonPressed;

    void Awake()
    {
        RateButton.SetActive(true);
        PlayerPrefs.GetInt("ButtonPressed");
       
    }

    public void OpenURL()
    {
        Application.OpenURL("http://play.google.com/");
        Debug.Log("is this working?");
        PlayerPrefs.SetInt("ButtonPressed", 1);
        RateButton.SetActive(false);
        PlayerPrefs.Save();

    }
}

I’ll try to understand HasKey some more!

In case anyone comes here in future, this does the job:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RateGame : MonoBehaviour
{

    public GameObject RateButton;
    public int ButtonPressed;

    void Awake()
    {
        RateButton.SetActive(true);
        PlayerPrefs.GetInt("ButtonPressed");
        if (PlayerPrefs.GetInt("ButtonPressed") == 1)
            {
            RateButton.SetActive(false);
               
            }


    }

    public void OpenURL()
    {
        Application.OpenURL("http://play.google.com/");
        Debug.Log("is this working?");
        PlayerPrefs.SetInt("ButtonPressed", 1);
        RateButton.SetActive(false);
        PlayerPrefs.Save();

    }
}

@Dommo1

BTW - Your code line 14 doesn’t do anything;

PlayerPrefs.GetInt("ButtonPressed");

You just run PlayerPrefs.GetInt but don’t store it anywhere. Only the if sentence matters where you get and compare the received value.

Oh haha! Thanks i’ll remove it… Now I look at it slowly that makes sense cheers