I have a sphere set as a trigger with this script attached:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EndGame : MonoBehaviour {
// Use this for initialization
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag (“FPSController”)) {
Application.LoadLevel (0);
}
}
}
When I go to where the collider is in game mode nothing happens. What am I missing?
Does the gameobject with the FPS controller have a rigidbody attached to it?
This is the newer API for switching scenes, btw: Unity - Scripting API: SceneManagement.SceneManager.LoadScene
I guess the older one is still working, but doesn’t hurt to know about this, in case it’s removed in the future, ya know?
Yes there is a rigidbody attached to the FPS Controller. I did try the SceneManger script but I get the compiler error that “SceneManager” does not exist in the current context.
Solved the “SceneManager” error I mentioned by adding “using UnityEngine.SceneManagement;” to the top.
But it still is not doing anything when I enter the area that the script is supposed to be attached to.
The script now looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class EndGame : MonoBehaviour {
// Use this for initialization
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag (“FPSController”)) {
SceneManager.LoadScene (“Maze”);
}
}
}
SOLVED!!!
I forgot to actually add the tag to the FPSController object. It feels awesome to solve this stuff. Thanks for the help guys.
Cool, glad ya solved it. I was about to ask you a couple of questions, before I saw the bottom part of your post with it Solved. lol
1 Like