- Home /
Loading Next Scene based on scores
Hello! I am having problems with writing a C#script. I want to write a script that stores player's scores (for entire game) based on GUI buttons. Also, load next and specific scenes based on player's score. I have two score system: 1) Good point 2) Bad point if player clicks GUI button that is tagged with Good, player gets 1 good point, and same rule applies for bad point. If player clicked good point more than bad point, then happy ending scene appears on screen. If not, game over screen appears.
This is my script so far:
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class UsingPlayerPrefs : MonoBehaviour {
public int GoodPoint;
public int BadPoint;
public int finalGoodpoint;
public int finalbadpoint;
public int finalpoint;
public Text GoodPointText;
public Text BadPointText;
public string Bad;
public string Good;
public string ScoreName = "";
void OnGUIClick ()
{
Update ();
if (gameObject.CompareTag ("Good")) {
GoodPoint = GoodPoint + 1;
GoodPointText.text = "Good Point: " + goodpoint.ToString ();
}
Update ();
if (gameObject.CompareTag ("Bad")) {
BadPoint = BadPoint + 1;
BadPointText.text = "Bad point: " + BadPoint.ToString ();
}
}
void Update() {
int sum = BadPoint + GoodPoint;
//loading first scene
if (GoodPoint + BadPoint == 4) {
Application.LoadLevel ("scene1");
}
//load second scene
if (sum == 7) {
if (GoodPoint > BadPoint) {
Application.LoadLevel ("goodscene1");
}
else if ("badscene1");
}
//loading third scene
if (sum == 13) {
if (GoodPoint > BadPoint) {
Application.LoadLevel ("goodending");
} else if ("badending");
}
}
//saving Good points, and Bad points
class Program { static void AddTwoNumbers (int peaceScore, int warScore){ int sum = GoodPoint + BadPoint; PlayerPrefs.SetInt ("sum", sum); PlayerPrefs.Save (); } }
void GetData(){
GoodPoint = PlayerPrefs.GetInt ("GoodPoint");
ScoreName = PlayerPrefs.GetString ("ScoreName", "N/A");
Debug.Log ();
Debug.Log ();
}
}
Can anyone help me with this? I want to load different scene based on scores and save scores by using PlayerPrefs. Please let me know if this cannot happen in one C# script.
Your answer
Follow this Question
Related Questions
Saving Stream to PlayerPref then unpack in new scene. 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers