Need Help with a Level Reloading Script (c#)
Okay so basically I am extremely new to Unity and c#, and I am trying to create a script so when my character collides with the object under the map, called Respawn, the scene reloads (It is a platformer). The script compiles fine, but when I run the game, the player just falls right through the respawn object, and nothing happens.
The character itself has both a Rigidbody and a mesh collider, with convex and trigger enabled. The object under the map has a mesh collider that is both convex and a trigger
I am also not sure if this should go in the player or the respawn object
here is the script:
using UnityEngine;
using System.Collections;
public class Respawn : MonoBehaviour
{
public GameObject spawnPoint;
void OnTriggerEnter(Collider other)
{
if (other.transform.name == "FPSController")
{
UnityEngine.SceneManagement.SceneManager.LoadScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
}
}
}
Please note that this script has been pieced together over a series of days and with the help of dozens of tutorials and/or other help topics. Please assist me!
using UnityEngine;
using System.Collections;
using UnityEngine.Scene$$anonymous$$anagement;
if(other.gameObject.name == "FPSController")
{
Scene$$anonymous$$anager.GetActiveScene().name);
}
Answer by jorgeguimaraes · Mar 02, 2016 at 11:06 PM
Try this:
using UnityEngine;
using UnityEngine.SceneManagement;
if (other.transform.name == "FPSController")
{
Scene actualScene = SceneManager.GetActiveScene();
SceneManager.LoadScene(actualScene.name.ToString());
}