Hello , I will like a little bit of help regarding a game that I create.
Idea is that I am pretty new in programming just as a hobby and my game have scrolling background. I have different scenes that I will like to add to my game play as If the player make a 50 score to create a pop up with a button that will launch the new scene but keeping also the score from the previous one. Also when my hero dies I will like to start the game on click with the initial scene and score to be again 0. I am loosing it and cannot do this to work proper.
-using UnityEngine;
-using System.Collections;
-using UnityEngine.UI;
-using UnityEngine.SceneManagement;
public class GameControl : MonoBehaviour
{
public static GameControl instance;
public Text scoreText;
public Text highScoretext;
public GameObject gameOvertext;
private int score = 0;
public string CongratulationsMenu;
public bool gameOver = false;
public float scrollSpeed = -1.5f;
void Start()
{
highScoretext.text = "High score: " + ((int)PlayerPrefs.GetFloat("HighScore")).ToString();
// score = PlayerPrefs.GetInt("Score");
}
void Awake()
{
if (instance == null)
instance = this;
else if (instance != this)
Destroy(gameObject);
}
void Update()
{
if (gameOver == true && Input.GetMouseButtonDown (0))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
if(score >= 3)
{
NewWorld();
}
// scoreText.text = "Score: " + score; PlayerPrefs.SetInt("Score", score);
}
public void HeroScored()
{
//The bird can't score if the game is over.
if (gameOver)
return;
//If the game is not over, increase the score...
score++;
//...and adjust the score text.
scoreText.text = "Score: " + score.ToString();
}
public void HeroDied()
{
//Activate the game over text.
gameOvertext.SetActive(true);
//Set the game to be over.
gameOver = true;
if (PlayerPrefs.GetFloat("HighScore") < score)
PlayerPrefs.SetFloat("HighScore", score);
}
public void NewWorld()
{
Time.timeScale = 1f;
// PlayerPrefs.SetFloat("Score", score);
PlayerPrefs.SetFloat("HighScore", score);
//scoreText.text = "Score: " + score; PlayerPrefs.SetInt("Score", score);
SceneManager.LoadScene(CongratulationsMenu);
}
}
the commented code is some of what i have worked with, Could some of you that have experience may help me ? Thank you in advance.
Your answer
Follow this Question
Related Questions
Multiple Entrances to levels 0 Answers
Load level once 0 Answers
Scene is loading in Game Mode, but not in the build. Why? 2 Answers