SU MI
SU MI

Reputation: 1

Error "The name does not exist in the current context", Unity

In the function OnTriggerEnter2D I faced the error: "The name "collision" does not exist in the current context". Here is my code:

public int iLevelToLoad;
public string sLevelToLoad;

public bool useIntegerToLoadLevel = false;

private void OnTriggerEnter2D (Collider2D collison)
{
    GameObject collisionGameObject = collision.gameObject;

    if(collisionGameObject.name == "Player")
    {
        LoadScene();
    }

}

void LoadScene ()
{
    if (useIntegerToLoadLevel)
    {
        SceneManager.LoadScene(iLevelToLoad);
    }
    else
    {
        SceneManager.LoadScene(sLevelToLoad);
    }
}

Upvotes: 0

Views: 4102

Answers (1)

kogonidze
kogonidze

Reputation: 157

You pass as the parameter of OnTriggerEnter2D() function variable collison, but in function you trying to call collision. It is just a misprint. Change the parameter name as collision.

Upvotes: 1

Related Questions