Making a high score script
im trying to make a 2d game where you collect little candies and you get points i have a point scripts and a restart script but when you die i want it to open up a scene Saying You died and it shows the highscore how would i save the score
Score script :
using UnityEngine; using System.Collections;
public class ScoreSystem : MonoBehaviour { public int Score;
void Start ()
{
Score = 0;
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Candy")
{
Debug.Log("Collided");
Score += 1;
OnGUI();
}
}
void OnGUI() {
GUI.Label(new Rect(10, 10, 100, 20), "Score: " + Score);
}
}
Restart Script:
using System; using UnityEngine;
namespace UnityStandardAssets._2D { public class Restarter : MonoBehaviour { private void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { Application.LoadLevel(Application.Death); } } } }
Your answer
Follow this Question
Related Questions
How do I make a Score and Highscore thingie in game over screen 2 Answers
Moving left and right with one button in 2d Game 1 Answer
How To Do Basic 2D Movement? 1 Answer
How to move the player only 1 tile per buttonPress? 2 Answers
Making a list of images within a scrollrect generated from prefabs tappable/clickable 1 Answer