x


Why does my trigger work in the editor but not in the .exe?

Hello, I have this really weird problem with my game. So I have this game object, the boss of the level, that instantiates an object (access card) with a trigger that sets a variable to true for another trigger object (Show Map). With it's variable set to true it calls an iTween Path function and ends the level.

This all works when I'm testing the game in the editor but if I run it in as an .exe it works until I trigger the access card and the Show Map trigger will do absolutely nothing and it is impossible to go to the next level.

Here is the code for the access card object if it would help you:

 using UnityEngine;
 using System.Collections;
 
 public class AccessCard : MonoBehaviour {
 
     // Use this for initialization
     public int up = 8;
     public int down = 2;
     
     void Start () 
     {
             iTween.MoveTo(gameObject, iTween.Hash("y",up,"time",0.5));
             iTween.MoveTo(gameObject, iTween.Hash("y",down,"time",3,"delay",0.5));
     }
     
     // Update is called once per frame
     void Update () 
     {
             shield1 = GameObject.Find("Shield1");
             shield2 = GameObject.Find("Shield2");
             shield3 = GameObject.Find("Shield3");
         
             transform.Rotate(0,15,0);
             if(shield1.transform.position.y == 112)
             {
                     Destroy(shield1.gameObject);
             }
             if(shield2.transform.position.y == 112)
             {
                     Destroy(shield2.gameObject);
             }
             if(shield3.transform.position.y == 112)
             {
                     Destroy(shield3.gameObject);
             }
     }
     
     void OnTriggerEnter (Collider collider)
     {
         if(collider.tag == "Player")
         {
             ShowMap1.canTrig = true;
             RemoveShields();
             Destroy(gameObject);
         }
     }
     
     private GameObject shield1;
     private GameObject shield2;
     private GameObject shield3;
     private GameObject bossDoor;
     
     void RemoveShields ()
     {
             shield1 = GameObject.Find("Shield1");
             shield2 = GameObject.Find("Shield2");
             shield3 = GameObject.Find("Shield3");
             bossDoor = GameObject.Find("BossDoor");
         
             iTween.MoveTo(shield1.gameObject, iTween.Hash("y",112));
             iTween.MoveTo(shield2.gameObject, iTween.Hash("y",112));
             iTween.MoveTo(shield3.gameObject, iTween.Hash("y",112));
             Destroy(bossDoor.gameObject);
     }
 }

And the Show Map trigger calling the iTween Path:

 using UnityEngine;
 using System.Collections;
 
 public class ShowMap1 : MonoBehaviour {
 
 public int time = 5;
 private bool playClip = false;
 private bool trig = false;
 public static bool canTrig = false;
 public GameObject cam;
 public GameObject planet;
 private bool denied = false;
 public bool secret = false;
 
 void Update ()
 {
         if(playClip)
         {
                 iTween.MoveTo(cam, iTween.Hash("path" , iTweenPath.GetPath("camPath"), "time", time));
                 playClip = false;
         }
         if(trig)
         {
                 cam.transform.LookAt(planet.transform.position);
         }
         if (cam.transform.position == new Vector3(0,-457.5542f,599.0647f))
         {
                 Application.LoadLevel(7);
         }
 }
 
 void OnTriggerEnter (Collider collider)
 {
     cam = GameObject.Find("Main Camera");
         
         if(collider.tag == "Player")
         {
                 if(secret)
                 {
                         Destroy(cam.GetComponent("SmoothFollow"));
                         playClip = true;
                         trig = true;
                 }
                 else
                 {
                         if(canTrig)
                         {
                                 Destroy(cam.GetComponent("SmoothFollow"));
                                 playClip = true;
                                 trig = true;
                         }
                         else
                         {
                                 denied = true;
                         }
                 }
         }
 }
 
 void OnTriggerExit ()
 {
         if(denied)
         {
                 denied = false;
         }
 }
 
 void OnGUI ()
 {
         if(denied)
         {
                 GUI.Box(new Rect(Screen.width/2-100,Screen.height/2-15,200,30), "Access Denied");
         }
 }
 }
 

Also I normally program in JavaScript not C# these are my only C# scripts so I could get the iTweenPath to work because iTweenPath isn't compatible with JavaScript last time I tried.

more ▼

asked Oct 31, 2012 at 12:29 AM

Laprasoul gravatar image

Laprasoul
227 87 79 93

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Okay Here is what I found out. Computers can be stupid sometimes compiling code. The place were I had the

 if(canTrig)

I had to change that to

 if(canTrig==true)

And then it all works!

more ▼

answered Nov 02, 2012 at 12:45 PM

Laprasoul gravatar image

Laprasoul
227 87 79 93

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1753
x195
x55

asked: Oct 31, 2012 at 12:29 AM

Seen: 765 times

Last Updated: Nov 02, 2012 at 12:45 PM