- Home /
Code behaving differently after LoadLevel()
I've tried searching, but can't find a solution.
I'm having an issue that I can't pin down. When I run my scene in the Editor, my code functions great, but when I load the scene from a different scene this code isn't working proper.
I'm using TK2D's UI buttons as touch controls for the game and this function is supposed to be called when I release the "firing" button to make sure I don't get an out of bounds exception with my other touches. If the fingerID of the other touches is greater than the one released it will lower the ID of the other touches. Again, this seems to work great when I build the scene by itself, but when it's being loaded this function stops working.
I'm definitely a noob to programming and even more so to Unity, so maybe i'm just going about this all the wrong way. But here's the code:
void FireUp ()
{
RecalcTouch (fireFinger);
fireFinger = -32; //this is the null state
}
void RecalcTouch (int released)
{
if (dPadFinger > released) {
Debug.Log ("dPadFinger (" + dPadFinger + ") > released (" + released + ")");
dPadFinger--;
}
if (sPadFinger > released)
sPadFinger--;
}
Hopefully I wrote this question and stuff right. It's my first. Thanks for the help...
It doesn't seem like it, but maybe this is just a tk2d problem...
I see nothing here to account for this. When you load from the other scene, are there prefabs, instantiated "master" objects (like Game$$anonymous$$aster, Player, etc) that have DontDestroyOnLoad attached (or static vars) that might be causing conflicts?
Hey thanks for the reply... I was waiting for my question to be approved so I could post the answer.
This was entirely a T$$anonymous$$2D thing. For anyone out there who isn't familiar with T$$anonymous$$2D, they have a UI$$anonymous$$anager prefab that doesn't get destroyed in LoadLevel. Also, in the newer versions of T$$anonymous$$2D you don't absolutely need the UI$$anonymous$$anager. Their UICamera prefab will substitute this.
What was happening was that the UICamera in the first scene was getting selected as the UI$$anonymous$$anager and was deleting my $$anonymous$$anager in my second scene. Hence, I wasn't getting any errors, but I was losing some of my settings.
So, all I did was cut my manager from my second scene and paste it in the first. So... thanks again... you're exactly right, T$$anonymous$$2d's UI $$anonymous$$anager acts as a "master" object. Cheers.
Your answer
Follow this Question
Related Questions
Levels changing with UI best practice 2 Answers
Clear presses from previous scene 4 Answers
Input registering random touches 1 Answer