Script not working for me
I'm using the script below to change levels within my game but nothing is happening, I could use some assistance in solving the error which displays: "Script error: OnTriggerEnter2D This message parameter has to be of type: Collider2D"
Here is the script I'm using:
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public string level = "Stage 2";
// Use this for initialization
void OnTriggerEnter2D (Collision2D Collider)
{
if (Collider.gameObject.tag == "Player") {
Application.LoadLevel (level);
}
}
Answer by Namey5 · Oct 04, 2016 at 12:26 PM
void OnTriggerEnter2D (Collision2D col)
{
if (col.gameObject.tag == "Player") {
Application.LoadLevel (level);
}
}
'Collider' is a name reserved for a class in Unity, and as such you cannot use it in a variable reference.
Answer by ScaniX · Oct 04, 2016 at 04:18 PM
The signature of that method is wrong:
void OnTriggerEnter2D (Collision2D Collider)
and should be this instead:
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player") {
Application.LoadLevel (level);
}
}
Your answer
Follow this Question
Related Questions
level manger and starting scene will not work together 0 Answers
Help with Script 0 Answers
Player not moving in the right direction instantly 1 Answer
Issue toggling Particle system on/off using bool. 1 Answer
Adding a Highscore to game 1 Answer