Question by
TeenChiummo · Mar 17, 2017 at 03:50 PM ·
scripting problemint
HighScore and int!
Hi!I'm new in the script'context , i have done this script, but unity doesn't create the highscore file , i don't know how get my Int definition of score from my GameScore script (the score int isn't a static int)
please help me :(
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public Text HighScoreGO;
public GameObject enemySpawner;
public GameObject playButton;
public GameObject playerShip;
public GameObject GameOverGO;
public GameObject scoreUITextGO;
public GameObject TimeCounterGO;
public GameObject ShootButton;
int score;
public enum GameManagerState
{
Opening,
Gameplay,
GameOver,
}
GameManagerState GMState;
// Use this for initialization
void Start()
{
GMState = GameManagerState.Opening;
score = GameScore.Score2;
}
void UpdateGameManagerState()
{
switch (GMState)
{
case GameManagerState.Opening:
GameOverGO.SetActive(false);
playButton.SetActive(true);
HighScoreGO.text = ((int)PlayerPrefs.GetFloat("highscore")).ToString();
break;
case GameManagerState.Gameplay:
scoreUITextGO.GetComponent<GameScore>().Score = 0;
playButton.SetActive(false);
playerShip.GetComponent<PlayerControl>().Init();
enemySpawner.GetComponent<EnemySpawner>().ScheduleEnemySpawner();
TimeCounterGO.GetComponent<TimeCounter>().StartTimeCounter();
ShootButton.SetActive(true);
break;
case GameManagerState.GameOver:
TimeCounterGO.GetComponent<TimeCounter>().StopTimeCounter();
enemySpawner.GetComponent<EnemySpawner>().UnscheduleEnemySpawner();
ChangeHighScore();
Invoke("ChangeToOpeningState", 6f);
GameOverGO.SetActive(true);
ShootButton.SetActive(false);
break;
}
}
public void SetGameManagerState(GameManagerState state)
{
GMState = state;
UpdateGameManagerState();
}
public void StartGamePlay()
{
GMState = GameManagerState.Gameplay;
UpdateGameManagerState();
}
public void ChangeToOpeningState()
{
SetGameManagerState(GameManagerState.Opening);
}
public void ChangeHighScore()
{
if (PlayerPrefs.GetFloat("highscore") < score)
{
PlayerPrefs.SetFloat("highscore", score);
}
}
}
Comment