C# script too big for Android?

Hello

I’m working on a game. Currently I’m doing main menu. Today When I pushed game to a phone I got a forced close on start, just in time when Main menu and it’s script is supposed to start.

I have my MainMenu done like that :

 if (menuType == "credits") {  // *************      Credits     Screen       *************
 						if (menuStep == 0 ) {  // *************      Animation IN     Credits     *************
								timer = (Time.time - menuTime) * 5;
                
                // some animations here using timer and Lerp
 
								if (timer > 2) {
										menuStep = 1;
										menuTime = Time.time;
								}
						}


						if (menuStep == 1) { // *************      Action     Credits     *************
								button2.guiTexture.texture = buttons [6];

								if (Input.GetKeyUp (KeyCode.Escape)) {
										menuTime = Time.time;
										menuStep = 2;
								}
								
								int i = 0;
								while (i < Input.touchCount) {
								
										if (Input.GetTouch (i).position.x > button2.guiTexture.pixelInset.x &&
										    Input.GetTouch (i).position.y < Screen.height * 13 / 48)
												button2.guiTexture.texture = buttons [7];
												
										if (Input.GetTouch (i).phase == TouchPhase.Ended) {
										
												if (Input.GetTouch (i).position.x > button2.guiTexture.pixelInset.x &&
												    Input.GetTouch (i).position.y < Screen.height * 13 / 48) {
														menuStep = 2;
														menuTime = Time.time;
												}
										}
										++i;
								}
						}
				
						if (menuStep == 2) {  // *************      Animation Out  - back to Main Menu    *************
								timer = (Time.time - menuTime) * 5;
                
                // some animations here using timer and Lerp
 
								if (timer > 2) {
										menuType = "main";
										menuStep = 0;
										menuTime = Time.time;
								}
						}
				}

So basicaly I have couple of IFs in Update(), dependand on menuType, and inside every IF, actions dependand on MenuStep.

And it works great. And worked great on phone also (phone is galaxy S I9000). Until today when I got forced close on start on a phone (it works good on PC).

I figured out, that the problem are the last two menuType IF’s. The other one is identical to that one I pasted here, it just use different label. They are empty for now.

I got to a point that the line that makes the problem is:

if (Input.GetTouch (i).phase == TouchPhase.Ended) {

 if (Input.GetTouch (i).position.x > button2.guiTexture.pixelInset.x &&
  Input.GetTouch (i).position.y < Screen.height * 13 / 48) {

the third line, which is second condition in that IF. There is nothing wrong with that line. But it ferces close. When I replace this condition with TRUE, it works, but then the next thing causes force close. It’s like thats a limit of a script that phone can handle. If I comment out some other IF earlier in the code, then these ones works allright. It’s definetely a script length problem. The script is 3761 lines and its ~200kb. I didn’t know there could be a script limit. It’s not like the whole script is active all the time. Only one single MenuStep in one MenuType works at a time. So it’s not performance problem. Besides it works great if I comment out these 2 last IF’s. The problem is when I guess she script is somehow compiled on a phone or something. Is there something I can do about it?
I know I9000 is old phone, and probably if I tried it on some other, newer phone it wouldn’t be a problem, but the whole game works great even on that phone if it works, so it would be a shame to rule out older phones just because the script is too long. Is there something I can do to make it work even on that old phone? I mean, is 4K lines script really that unusual?!

Yeah, I think its something with memory also, but its connected with script length.

If I have:

Update()

if menuType == main
   menuStep 0 - animation in
   menuStep 1 - action in menu
   menuStep 2 - animation Out

else if menuType == settings
   menuStep 0 - animation in
   menuStep 1 - if touch go to CameraSettings or to controlsSettings
   menuStep 2 - animation Out

else if menuType == CameraSettings

and so on. Two last IFs are Help and Credits, which are empty for now. They only have 3 steps, IN, Touch (to exit), and OUT. They dont work until I choose one of the options in menu.
And now on phone app wont wor because of them. If I comment out Some portion of code Before them, it works. And they work alright. Its like, I can have 1000 lines in Update, if I go over this > error. Doesn’t matter if its Credits or something else.

I tried to redo all this from IF to Switch. No luck.

I will try to do it witch methods. Now I have everything in Update. I will try to make swhitch witch menuType and if menuType == X, then start Method X where will be the code that was in Update. Maybe this will help.

Modularisation is alright. As I said, in editor it works great. On phone also, If I reduce number of active lines by commenting something.


About errors in Unity console I dont get any, but I never do. Even If I have some simple error that doesnt close application, like division by 0, if I test it in editor I got error, but when I buid&run, and test it on the phone (connected to PC of course) I never get anything in Unity console. Is it possible to run game on the phone (not by remote. on the phone) and get all the things in console like if I test game in editor? like debug.log or print? I’ve searched internet about that but I couldnt find is it possible and if so, how to do it. When I got that error today I just commented every If, one by one, build and run, and checkt if it helped. Is there a way to get messages from game on the phone in Unity editor console?

I checked logcat but honestly it’s magic for me.

http://pastebin.com/GTjXS7qK

If I filter it to Unity only (-s Unity) I get nothing.