0
\$\begingroup\$

I made a game and I made a Magnet upgrade and I have 8 game objects to set active 1 by 1 every time when I upgrade the magnet and I have (int upgrade = 0;).

But when I upgrade these game objects it's set active, but if I quit the game and start again all these game objects are FALSE.

How can I make e.g if I upgrade to (int upgrade = 6) and to make my game objects active only from element 0 to element 6. I do upgradeMagnet(); to void Update but its make active only 1 game object depends from (int upgrade) if (int upgrade) is 5 and only game object element 5 is active.

screenshot

 public GameObject[] upgranded; public int upgrade = 0; public void upgrandeMagnetButton() { upgrade += 1; upgradeMagnet(); } void upgradeMagnet() { if (upgranded[upgrade]) { upgranded[upgrade].SetActive(true); } } 
\$\endgroup\$
3
  • \$\begingroup\$ You should store your upgrade value in player preference and read from that. \$\endgroup\$ Commented Nov 24, 2017 at 15:50
  • \$\begingroup\$ i made that but its show only one game object e.g. if upgrade value is 5 and its show game object element 5. \$\endgroup\$ Commented Nov 24, 2017 at 16:39
  • \$\begingroup\$ I don't see it in your snippet. In the Start function simply set a for loop to activate all items. \$\endgroup\$ Commented Nov 24, 2017 at 16:42

1 Answer 1

1
\$\begingroup\$

simply activate them in your start.

void Start(){ upgrade = load from player prefs here int count = upgrade+1; for(int i = 0; i < count; i++){ upgranded[i].SetActive(true); } } 
\$\endgroup\$
5
  • \$\begingroup\$ I wrote this before but didn`t work give me a NullReference error. \$\endgroup\$ Commented Nov 24, 2017 at 17:03
  • 1
    \$\begingroup\$ You need to spend a bit more time learning basic C# and basic syntax. Your first element in your array is empty. \$\endgroup\$ Commented Nov 24, 2017 at 17:05
  • \$\begingroup\$ Thanks now work all fine but last game object it`s stay always false after load playerprefs. \$\endgroup\$ Commented Nov 24, 2017 at 17:28
  • \$\begingroup\$ E.g. if i upgrade value 4 after reload the game and go to upgrade its shows 3 value game object and 4 its doesn`t show. \$\endgroup\$ Commented Nov 24, 2017 at 18:41
  • \$\begingroup\$ int count = upgrade+1 and use count in the for loop instead of upgrade. Check the edit. Or you can simply use = instead of < \$\endgroup\$ Commented Nov 24, 2017 at 18:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.