Reputation: 11
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
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