Advertisement
Guest User

OnTriggerEnter Not working

a guest
Apr 30th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. //this is the trigger
  2.  
  3.  
  4. using UnityEngine;
  5.  
  6. public class endtrigger : MonoBehaviour {
  7.  
  8.     public GameManagerScript gameManager;
  9.  
  10.  
  11.     void OnTriggerEnter ()
  12.     {
  13.         gameManager.CompleteLevel();
  14.     }
  15.        
  16. }
  17.  
  18.  
  19.  
  20. //this is the game manager in a separate script
  21.  
  22. using UnityEngine;
  23. using UnityEngine.SceneManagement;
  24.  
  25. public class GameManagerScript : MonoBehaviour {
  26.  
  27.     bool gamehasended = false;
  28.  
  29.     public float restartDelay = 1f;
  30.  
  31.     public GameObject completeLevelUI;
  32.  
  33.     public void CompleteLevel ()
  34.     {
  35.         completeLevelUI.SetActive(true);
  36.         Debug.Log ("LEVELDONE");
  37.     }
  38.  
  39.     public void endgame ()
  40.     {
  41.         if (gamehasended == false)
  42.         {
  43.             gamehasended = true;
  44.             Debug.Log("GAME OVER");
  45.             Invoke("Restart", restartDelay);
  46.         }
  47.     }
  48.  
  49.     void Restart ()
  50.     {
  51.         SceneManager.LoadScene(SceneManager.GetActiveScene().name);
  52.         Debug.Log("RESTARTED");
  53.     }
  54.  
  55. }
  56.  
  57.  
  58. //my bug report (has a typo)
  59. https://fogbugz.unity3d.com/default.asp?906597_eqkj43md65n1l36o
  60.  
  61. //brackeys forum (I was following his tutorial)
  62.  
  63. http://forum.brackeys.com/thread/ontriggerenter-not-working-2/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement