Please help how to save last index and load

Updated on March 13, 2017 in [A] GUI
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on March 12, 2017

Hi everyone

can someone smart show me how to save last activated gun or last index got activated in playerprefs i m pretty new in coding and stupid, so please don’t tell how to do it, show me ūüėÄ thanks for help and sorry for my bad english..

public class TestGun : MonoBehaviour
{
    public GameObject[] gun;
    public int activeIndex = 0;
    public void SetActiveObject(int aIndex)
    {
        activeIndex = aIndex;
        for (int i = 0; i < gun.Length; i++)
            gun[i].SetActive(i == activeIndex);
    }
    void Update()
    {
        SetActiveObject(activeIndex);
    }
    public void UpgradeButtom()
    {
        gun[activeIndex].SetActive(true);
        activeIndex++;
    }
}
  • Liked by
Reply
0 on March 13, 2017
working some how
public class testest : MonoBehaviour
{

    public GameObject[] gun;

    public int activeIndex = 0;
    void Start()
    {

¬†¬†¬†¬†¬†¬†¬†¬†activeIndex¬†=¬†PlayerPrefs.GetInt(“guns”);

    }

    public void SetActiveObject(int aIndex)
    {

        activeIndex = aIndex;
        for (int i = 0; i < gun.Length; i++)

            gun[i].SetActive(i == activeIndex);

¬†¬†¬†¬†¬†¬†¬†¬†PlayerPrefs.SetInt(“guns”,¬†activeIndex);

    }

    void Update()
    {

        SetActiveObject(activeIndex);

    }

    public void UpgradeButtom()
    {
        activeIndex++;
    }
}
  • Liked by
Reply
Cancel