- Home /
I want the player to move on to the next level once it has collected a coin. What would the script for that be?
Do you have something already and need help on a specific part? If so, explain where you're stuck. If not - use google and the unity forum. On Unity answers you can ask about specific problems not requesting finished scripts :)
However you would first create a coin with a collider on it. Same goes for the player. On your player you would place something like:
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "Coin")
{
Application.LoadLevel("nextLevelName");
}
}
You need to set the tag of the coin to Coin to make this work. You can also set the collider to trigger and use OnTriggerEnter
Here is the same with Javascript. Add this to the Coin and name your character as Player. Select the "is trigger" in the collider settings of the coin.
#pragma strict
function Start () {
}
function Update () {
}
function OnTriggerEnter (other : Collider)
{
if (other.collider.gameObject.tag == "Player")
{
Application.LoadLevel("TheNameOfTheNextScene");
}
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
getting a variable from another script problem 1 Answer
Change skybox at runtime? 2 Answers
Assigning varaibles to prefabs 1 Answer
2D Player Spawn Issue 0 Answers