x


points system with coins

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

more ▼

asked Apr 21, 2011 at 02:00 AM

jacques 1 gravatar image

jacques 1
39 36 31 37

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Script 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.

more ▼

answered Apr 21, 2011 at 03:45 AM

Alex 9 gravatar image

Alex 9
79 58 38 42

what do i do? it says trying to Invoke method: ScoreSystem.myFunction couln't be called

Apr 21, 2011 at 09:27 PM jacques 1

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!

Dec 08, 2012 at 09:31 AM himanshu619
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x323
x212
x82
x27
x22

asked: Apr 21, 2011 at 02:00 AM

Seen: 3749 times

Last Updated: Dec 08, 2012 at 09:31 AM