• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by aayucool2012 · Mar 12, 2013 at 03:12 PM · raycastraycasthitmainmenu

Main Menu not responding to touch on Android

Hi, I've been following tutorials on how to make a dx ball type game for android but now I am running into a problem. When I test the game on my android phone(HVGA Landscape)the menu screen comes and when I tap on the start button the game hangs for a while and then suddenly starts,strange though this does not happen while on pc. Here is my menu script:-`#pragma strict

private var ray : Ray; private var hit : RaycastHit;

function Update () {

 if(Input.GetMouseButtonDown(0))
 {
     ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     if(Physics.Raycast(ray,hit)){
     if(hit.transform.name == "Start"){
     Application.LoadLevel("BrickBreakerSc1");
     }
     if(hit.transform.name == "Exit"){
     Application.Quit();
     }
     }
 }

}` this is the script which controls the menu

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Seth-Bergman · Mar 13, 2013 at 06:30 AM

Changing scenes is apparently rather costly with Android builds.. the PC has much more memory, so it can handle more..

The application is not really "hanging", just loading, depending on what you have in your project this can take a while.

my advice is to combine the menu into the game scene, then just toggle things on or off rather than changing scenes at all.. ENUMS are good for keeping track of a game state... so instead of:

  if(hit.transform.name == "Start"){
      Application.LoadLevel("BrickBreakerSc1");
  }

something like:

 enum GameState {menu,gameplay};

  var currentGameState : GameState;

 function Update () {
 ...etc
  if(hit.transform.name == "Start"){
     currentGameState = GameState.gameplay;
 }

otherwise, you can expect some delay in scene changes.. you may want to turn on a load screen if you decide to keep the separate scenes:

  if(hit.transform.name == "Start"){
     showLoadGUI = true;
     Application.LoadLevel("BrickBreakerSc1");
 }    

and then:

 function OnGUI(){
     if(showLoadGUI){
         GUI.DrawTexture(...etc);
        //some load screen code,change audio clip, etc...
     }
 }

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aayucool2012 · Mar 13, 2013 at 08:25 AM 0
Share

I think its a good idea, will try!

avatar image Fattie · Mar 13, 2013 at 08:34 AM 0
Share

indeed, it's generally a huge problem

when you first start making games it's like "oh I'll change scene"...

in the real world it's almost always much more complex than that.

say for example you're about to load all your menu-help-purchases-etc-crap screens.

typically you have to load, let's say, JUST the background of your upco$$anonymous$$g scene extravaganza, and the music. once that's actually running, you can start loading in perhaps the buttons and the 8 million sound effects, etc.

ideally, there'll be a stupid animation of the robot blowing up or whatever, that you can fill time with while loading the button textures, maybe - or whatever the case may be. in which case that's yet another "scene" you're loading, ti$$anonymous$$g, etc to "just load a scene"

if you look at really well made games, I mean games that have huge sales and have big $$anonymous$$ms of engineers on them so they are really highly developed, you will always see this sort of thing done really beautifully and with real care. But it all takes time and effort.

Again it's just one of those things where, when you first start out or are doing an experiment, it all sound so easy .. "Look, Unity says just load scene!" But it's much harder in real life. See what happens if you have a top 500 game with huge load times and a big stall while it loads! :-/

avatar image aayucool2012 · Mar 13, 2013 at 09:49 AM 0
Share

the onload gui helps a lot!! thanks

avatar image Seth-Bergman · Mar 13, 2013 at 10:48 PM 0
Share

yeah, I'm finishing up a game right now (Android) with a few thousand sprites, and the time to load scenes was really unwieldy.. But by combining the entire game into a single scene, load time is now nonexistent.. Only the initial launch is the only load screen..

avatar image aayucool2012 · Mar 14, 2013 at 05:27 AM 0
Share

yeah but it would have required a lot(and lot) of scripting

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is this way of making a raycast correct 2 Answers

RaycastHit2D.collider is null - why? 1 Answer

How do I change the raycasthit material back? 1 Answer

Raycasting will not hit some imported meshes with mesh colliders? 2 Answers

Physics.Raycast not hitting anything 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges