Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 RikuSoulz · Jan 07, 2015 at 07:03 PM · c#androiderrorbutton

Parsing Error, code in android for a button

Hello. I'm a completely beginner in unity and scripting. But I see tutorials and etc and I'm learning a lot. I'm now doing an Android Game. Now I have a code that will press a button and will for example do something like Load a Scene to start the game. A Start Game button and a Quit Game button.

My code is this:

 using UnityEngine;
 using System.Collections;
 var isQuitButton = false
 
 public class TestButton : TouchLogicV2 
 {
     public bool disableTouches;
     
     public override void Update()//(optional) only use Update if you need to
     {
         //you can do some logic before you check for the touches on screen
         
         if(!disableTouches)//(optional) dynamically change whether or not to check for touches
             base.Update();//must have this somewhere or TouchLogicV2's Update will be totally overwritten by this class's Update
     }
     
     public override void OnTouchBegan()
     {
         if( isQuitButton )
         {
             //QuitTheGame
             Application.Quit();
         }
         else
         {
             //LoadTheGame
             Application.LoadLevel("Test");
         }
     }
 }

But this gives me a Parsing Error... I think the error is inside public override void OnTouchBegan() and I say this because this other code works good:

 using UnityEngine;
 using System.Collections;
 
 public class TestButton : TouchLogicV2 
 {
     public bool disableTouches;
     
     public override void Update()//(optional) only use Update if you need to
     {
         //you can do some logic before you check for the touches on screen
         
         if(!disableTouches)//(optional) dynamically change whether or not to check for touches
             base.Update();//must have this somewhere or TouchLogicV2's Update will be totally overwritten by this class's Update
     }
     
     public override void OnTouchBegan()
     {
         print ("HELLO FROM TEST BUTTON!");
     }
 }

Can you explain me what am I doing wrong in a beginner form? Or can you say me a form to create a button that Starts the game and another to quit the game like a Main Menu? Thanks in advance!

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

2 Replies

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

Answer by MakinStuffLookGood · Jan 07, 2015 at 07:12 PM

You have a variable defined outside the class missing a semicolon. The full error message should point you directly to that.

Just move:

 var isQuitButton = false

into the scope of the class, and append a semicolon.

Comment
Add comment · 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
0

Answer by Ed unity · Jan 07, 2015 at 07:14 PM

You are missing a ; after the declaration of your variable and it is outside the scope of the class. It should be the following:

var isQuitButton = false;

However, in your code, please also keep in mind that nothing is changing the isQuitButton variable to true and thus, Application.Quit() will never be called.

Comment
Add comment · Show 1 · 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 RikuSoulz · Jan 08, 2015 at 09:12 AM 0
Share

Thank you very much, now my script works, I'm trying to work with a 3D Text with a Box Collider but that doesn't work.. but the script problem is solved. The Variable isQuitButton is if in the main menu the button is called Quit, then you change it on the Inspector.

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

UI works in editor, but not on mobile device 1 Answer

Why there is an 'SerializationException: serializationStream supports seeking, but its length is 0' error when I click the load button? 2 Answers

Compiler errors while switching to android 1 Answer

foreach (Touch touch in Input.touches) not working 1 Answer

Getting Buttons to change stage c# Add Listner 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