- Home /
Loading a level and moving a game object to a new scene on collision
I'm trying to get my player GameObject to teleport to a new scene when it collides with a Box Collider 2D on another GameObject. The only issue is that I get this error message:
...error CS1503: Argument 1: cannot convert from 'UnityEngine.SceneManagement.Scene' to 'string'
I'm using this code, which is pretty much a copy of what I had on a previous project. Any ideas?
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
using UnityEngine.UI;
public class TeleportPlayer: MonoBehaviour
{
public GameObject player;
public Vector3 teleportPos;
public Scene teleport;
void OnCollisionEnter2D(Collision2D col)
{
if(col.gameObject.tag == "player")
{
LoadLevel(teleport);
MoveGameObjectToScene(player, teleport);
}
}
public void LoadLevel(string name)
{
SceneManager.LoadScene(name);
}
}
Answer by IndyXD · Oct 19, 2019 at 01:48 AM
mate maybe you should just make a scene in build settings and go SceneManager.LoadScene(number of scene i want to switch to)
I want you to know, I jumped through all the hoops needed to sign up just to tell you this: You muppet, you completely ignore the core of the issue and do not in any way help with the issue!, it is especially bad since this is the first google hit. Remove your answer or fix it! You don't account for the teleportPos or teleport arguments in the above script. The only reason i did not downvote you is that i do not have the rep for it yet. But i will grind it just to downvote you!
Your answer
Follow this Question
Related Questions
Problem with 2D Collider Trigger 1 Answer
All of my doors are opening at the same time. Why? 0 Answers
Object hits another but doesnt bounce off again. 0 Answers
Ground dash is like a teleport 0 Answers