Search Unity

[SOLVED] Trying to create a simple return to main menu trigger

Discussion in 'UGUI & TextMesh Pro' started by AidanEOK, Apr 26, 2017.

  1. AidanEOK

    AidanEOK

    Joined:
    Apr 26, 2017
    Posts:
    13
    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?
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
  3. AidanEOK

    AidanEOK

    Joined:
    Apr 26, 2017
    Posts:
    13
    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.
     
  4. AidanEOK

    AidanEOK

    Joined:
    Apr 26, 2017
    Posts:
    13
    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.
     
    Last edited: Apr 27, 2017
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    :) 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
     
    AidanEOK likes this.