Question by
$$anonymous$$ · May 08, 2019 at 08:22 AM ·
c#triggerboxcollider2d
Problem with OnTriggerEnter2D() And OnCollisionEnter2D
HI!, i have a problem happens what i write OntriggerEnter2D or OnCollisionEnter2D in this script and the console says me "The Function has been declared but never used" PLZ HELP ME!
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.name == "Meta")
{
Destroy(Todo);
if (Nivel_1 == true)
{
SceneManager.LoadScene("Level_1", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 0);
}
if (Nivel_2 == true)
{
SceneManager.LoadScene("Nivel_2", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 1);
}
if (Nivel_3 == true)
{
SceneManager.LoadScene("Nivel_3", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 2);
}
if (Nivel_4 == true)
{
SceneManager.LoadScene("Nivel_4", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 3);
}
if (Nivel_5 == true)
{
SceneManager.LoadScene("Nivel_5", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 4);
}
if (Nivel_6 == true)
{
SceneManager.LoadScene("Nivel_6", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 5);
}
if (Nivel_7 == true)
{
SceneManager.LoadScene("Nivel_7", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 6);
}
if (Nivel_8 == true)
{
SceneManager.LoadScene("Nivel_8", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 7);
}
if (Nivel_9 == true)
{
SceneManager.LoadScene("Nivel_9", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 8);
}
if (Nivel_10 == true)
{
SceneManager.LoadScene("Nivel_10", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 9);
}
if (Nivel_11 == true)
{
SceneManager.LoadScene("Nivel_11", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 10);
}
if (Nivel_12 == true)
{
SceneManager.LoadScene("Nivel_12", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 11);
}
if (Nivel_13 == true)
{
SceneManager.LoadScene("Nivel_13", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 12);
}
if (Nivel_14 == true)
{
SceneManager.LoadScene("Nivel_14", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 13);
}
if (Nivel_15 == true)
{
SceneManager.LoadScene("Nivel_15", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 14);
}
if (Nivel_16 == true)
{
SceneManager.LoadScene("Nivel_16", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 15);
}
if (Nivel_17 == true)
{
SceneManager.LoadScene("Nivel_17", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 16);
}
if (Nivel_18 == true)
{
SceneManager.LoadScene("Nivel_18", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 17);
}
if (Nivel_19 == true)
{
SceneManager.LoadScene("Nivel_19", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 18);
}
if (Nivel_20 == true)
{
SceneManager.LoadScene("Nivel_20", LoadSceneMode.Single);
PlayerPrefs.SetInt("Niveles", 19);
}
}
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.name == "limites")
{
GameOver();
}
if (collision.gameObject.name == "Pincho_1")
{
GameOver();
}
if (collision.gameObject.name == "Pincho_1_Blanco" || collision.gameObject.name == "Pincho_1_Blanco (1)"
|| collision.gameObject.name == "Pincho_1_Blanco (2)" || collision.gameObject.name == "Pincho_1_Blanco (3)"
|| collision.gameObject.name == "Pincho_1_Blanco (4)" || collision.gameObject.name == "Pincho_1_Blanco (5)"
|| collision.gameObject.name == "Pincho_1_Blanco (6)" || collision.gameObject.name == "Pincho_1_Blanco (7)"
|| collision.gameObject.name == "Pincho_1_Blanco (8)" || collision.gameObject.name == "Pincho_1_Blanco (9)"
|| collision.gameObject.name == "Pincho_1_Blanco (10)")
{
GameOver();
}
if (collision.gameObject.name == "Pincho_2_Blanco-Prefab" || collision.gameObject.name == "Pincho_2_Blanco"
|| collision.gameObject.name == "Pincho_2_Blanco (1)" || collision.gameObject.name == "Pincho_2_Blanco (2)"
|| collision.gameObject.name == "Pincho_2_Blanco (3)" || collision.gameObject.name == "Pincho_2_Blanco (4)"
|| collision.gameObject.name == "Pincho_2_Blanco (5)" || collision.gameObject.name == "Pincho_2_Blanco (6)"
|| collision.gameObject.name == "Pincho_2_Blanco (7)" || collision.gameObject.name == "Pincho_2_Blanco (8)"
|| collision.gameObject.name == "Pincho_2_Blanco (9)" || collision.gameObject.name == "Pincho_2_Blanco (10)")
{
GameOver();
}
}
Comment
Hello (Buenas :D)
I'm not sure, but this meesages are refeared to variables, not methods. CAn you post the error message?
This OnCollision and OnTrigger are being executed?
Bye.
Your answer
![](https://koobas.hobune.stream/wayback/20220612200925im_/https://answers.unity.com/themes/thub/images/avi.jpg)