Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

Problem Z Game Manager


Rekomendowane odpowiedzi

Opublikowano

Witam mam taki skrypt na menadżer gry:

using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour {

// Ustawienia
public int currentScore;
public int highscore;
public int tokenCount;
private int totalTokenCount;
public int currentLevel = 0;
public int unlockedLevel;

// Czas
public Rect timerRect;
public Color warningColorTimer;
public Color defaultColorTimer;
public float startTime;
private string currentTime;

// GUI Skin
public GUISkin skin;

// Token
public GameObject tokenParent;

private bool completed = false;
private bool showWinScreen = false;
public int winScreenWidth, winScreenHeight;

void Update()
{
  if (!completed)
  {
   startTime -= Time.deltaTime;
   currentTime = string.Format("{0:0.0}", startTime);
   if (startTime <= 0)
   {
    startTime = 0;
    //Application.LoadLevel("main_menu");
   }
  }
}

void Start()
{
  totalTokenCount = tokenParent.transform.childCount;

  if (PlayerPrefs.GetInt("Level Completed") > 0)
  {
   currentLevel = PlayerPrefs.GetInt("Level Completed");
  } else {
   currentLevel = 0;
  }

  
}

public void CompleteLevel()
{
  showWinScreen = true;
  completed = true;
}

void LoadNextLevel()
{
  if (currentLevel < 1)
  {
   currentLevel += 1;
   print (currentLevel);
   SaveGame();
   Application.LoadLevel(currentLevel);
  } else {
   print ("You win!");
  }
}

void SaveGame()
{
  PlayerPrefs.SetInt("Level Completed", currentLevel);
  PlayerPrefs.SetInt("Level " + currentLevel.ToString() + " score", currentScore);
}

void OnGUI()
{
  GUI.skin = skin;
  if (startTime < 5f)
  {
   skin.GetStyle("Timer").normal.textColor = warningColorTimer;
  } else {
   skin.GetStyle("Timer").normal.textColor = defaultColorTimer;
  }
  GUI.Label (timerRect, currentTime, skin.GetStyle ("Timer"));
  GUI.Label (new Rect(45,100,200,200), tokenCount.ToString() + "/" + totalTokenCount.ToString());

  if (showWinScreen)
  {
   Rect winScreenRect = new Rect(Screen.width/2 - (Screen.width *.5f/2), Screen.height/2 - (Screen.height *.5f/2), Screen.width *.5f, Screen.height *.5f);
   GUI.Box(winScreenRect, "Gratulacje");

   int gameTime = (int)startTime;
   currentScore = tokenCount * gameTime;
   if (GUI.Button(new Rect(winScreenRect.x + winScreenRect.width - 170, winScreenRect.y + winScreenRect.height - 60, 150, 40), "Kontynułuj"))
   {
    LoadNextLevel();
   }
   if (GUI.Button(new Rect(winScreenRect.x + 20, winScreenRect.y + winScreenRect.height - 60, 100, 40), "Wróć Do Menu"))
   {
    Application.LoadLevel("main_menu");
   }

   GUI.Label(new Rect(winScreenRect.x + 20, winScreenRect.y + 40, 300, 50), currentScore.ToString() + " Score");
   GUI.Label(new Rect(winScreenRect.x + 20, winScreenRect.y + 70, 300, 50), "Level " + currentLevel + " Zakończony");

  }
}
}

 

Wszystko było by ok gdyby na starcie wartość  "currentLevel"  nie zmieniałą się na 2. I tu prosze o pomoc :)


reklama.png

Opublikowano
void Start()
{
  totalTokenCount = tokenParent.transform.childCount;
  if (PlayerPrefs.GetInt("Level Completed") > 0)
  {
   currentLevel = PlayerPrefs.GetInt("Level Completed");
  } else {
   currentLevel = 0;
  }
  
}

Widocznie "Level Completed" jest większe od 0 i wtedy w currentLevel wpisujesz tą wartość. Nie mam pojęcia gdzie dokładnie są player prefy na windowsie, ale możesz sprawdzić jaka tam jest wartość.

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...