- Home /
Problem with 2D Collider Trigger
Hello, I do have a problem with my code. I am trying to teleport my character between 2 scenes (2D), but I am struggling. My code does not work. Can anyone please try to fix it? I've tried everything I could. Thanks.
Error: error CS1001:Identifier expected
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Teleport : MonoBehaviour
{
//This should be wrong because there is a red dot in Visual studio
void OnTriggerStay2D(Collider2D, col)
{
Scene currentScene = SceneManager.GetActiveScene();
string sceneName = currentScene.name;
if (col.tag == "Player")
{
SceneManager.LoadScene("Village", LoadSceneMode.Additive);
}
}
}
Answer by Shrikky23 · May 22, 2019 at 08:03 PM
void OnTriggerStay2D(Collider2D, col) cannot have 2 parameters.
Did you mean void OnTriggerStay2D(Collider2D col) ? Other pointers : Make sure the other object that is colliding has the tag player, maybe debug col.gameobject.name first?
Check if that gameobject has the tag? You are loading scene additively, is that what you want?
When you say teleport between two scenes, you mean go to next scene or do you want to keep the player persistent?
The error is gone. Thanks But for the script, I want to move my player to another scene, but the last one is rendered too.