i was planning on putting coins in my map for a car game i created. The goal is to collect all the coins to move on to the next place… I need a script so when my car runs into the coin (a sphere) a GUI text will say “Score: 1”… also I need a script so when my car runs into the last coin it will move on to the next level… if the coin can self destruct when its reached so you cant get the same coin multiple times that will also help… Thanks in advance… and also please explain if you would attach the script to the car or coin or what
I have the script you need but i would like to know exactly what scores you want in each level for example in each level how many coins will there be is it the same each time as in the code i will need to set the score for you currently the script i have allows you to hit coins increments a score and loads the next level which you choose on the script (it says next level you just type in there) so ill explain how to set up the current script let me know if you need it changing.
private var score: int = 0;
var GuiScore : GUIText;
var NextLevel : String;
function Start() {
GuiScore.text = "Score: 0";
}
function Update (){
if (score == 30) {
Application.LoadLevel(NextLevel);
}
}
function OnTriggerEnter(col : Collider)
{
if(col.tag == "Coin")
{
Destroy(col.gameObject);
score +=10;
GuiScore.text = "Score : " + score;
}
}
okay to settings up go to edit project settings Tags there will be a drop down arrow click it and add a new element and type into it Coin exact spelling it is case sensitive. now add a game object (sphere or coin object you have modeled) now go to tags on this object and set it to the coin tag we created. on the collider on this object set it to trigger. Now create a new Gui text (gameobject- create other - gui text) position as you want the text does not need setting its done in script. now add the script to the player.
Drag and drop guiText into the script.
set next level to the name of your next level (make sure it is in the build list or it says can not load as not in build settings).
and your done it currently only goes to score30 i dont know what score you want so ill tell you how to change that if you ask.
