Hector VDK
Hector VDK

Reputation: 11

Having trouble with my Level System for my platformer game

I'm making a level system for my platformer code and have run into an issue. I get the error:

cs1061 "collider 2D" does not contain a definition for 'GameObject' and no accessible extension method 'GameObject' accepting a first argument of type 'Collider2D' could be found..

I've looked around but do not understand this error. My code:

public int ILevelToLoad;
    public string sLevelToLoad;

    public bool useIntegertoLoadLevel = false; 
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        GameObject collisionGameObject = collision.GameObject;

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

    void LoadScene()
    {
        if (useIntegertoLoadLevel)
        {
        SceneManager.LoadScene(ILevelToLoad);
        }
        else
        {
            SceneManager.LoadScene(sLevelToLoad);
        }
    }

Upvotes: 0

Views: 32

Answers (1)

Hamid Yusifli
Hamid Yusifli

Reputation: 10137

The Collider2D class has no properties named GameObject, replace this line:

GameObject collisionGameObject = collision.GameObject;

with this:

GameObject collisionGameObject = collision.gameObject;

Upvotes: 0

Related Questions