hey guys what is a good script for passing through a coin getting a point, then coin is destroyed, and after so many points getting to a next level/beating the game please help this is one of my final touches but of corse a big part
3 Answers
3Script for the Coin
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == "Player"){
//add a tag to the player called Player, or just
//replace it with your tag if you already have one
ScoreSystem.myScore += 1;
Destroy(gameObject,0.0);
}
}
Attatch this Script anywhere but name the Script "ScoreSystem" (this is very important)
static var myScore = 0;
var DelayTime = 10;
function Start(){
myScore = 0;
Invoke("myFunction", DelayTime);
}
function OnGUI(){
GUI.Label(Rect((Screen.width / 2) + 20,10, 200, 30), "Score: " + myScore);
}
Attatch This Script Anywhere as well
function Update(){
if(ScoreSystem.myScore == 10){ //change the 10 to however many coins there will be
Application.LoadLevel("YouWon");//Make a scene named "YouWon" and add it to the build
}
I hope this helps. Please review this code and learn from it.
Using playerprefs could solve the problem of coins reloading.
PlayerPrefs.setint(“score”,myscore); //this will set the coin value
PlayerPrefs.Getint(“score”); // this will get the stored coin value
Soomla has pretty good Scoring system with lots of features icluding social sharing,achievements ,IAP and lot more for FREE, have look at it, http://soom.la/
Alex 9, can you tell that how the score of previous level would be added to next level starting score, Because it seams from your script that it would start with "zero" every-time!
– himanshu619using playerprefs would solve that.
– prajyothPlayerPrefs.Setint("score",myScore); //use this to save the score PlayerPrefs.Getint("score"); //use this to get the stored score