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 ukk · Mar 17, 2015 at 09:00 PM · androidguidebugdebug.log

Problem with android on screen GUI

Hello to everyone. I'm trying to create an onscreen control gui with a dpad and two buttons with the following code:

 public class GUIButtons : MonoBehaviour {
 
     private Rect DPadRect;
     private Rect RedButtonRect;
     private Rect BlueButtonRect;
 
     private Triangle ArrowUp;
     private Triangle ArrowDown;
     private Triangle ArrowLeft;
     private Triangle ArrowRight;
 
     private bool inputEnabled = true;
 
     public Texture DPad;
     public Texture RedButton;
     public Texture BlueButton;
 
     
 
     void Start () {
 
         // Initializes size of gui items
         DPadRect = new Rect(Screen.width/10,2*Screen.height/3 - Screen.height/8,Screen.width/5,Screen.width/5);
         RedButtonRect = new Rect(2 * Screen.width / 3, 2 * Screen.height / 3 - Screen.height/10 , Screen.width / 8, Screen.width / 8);
         BlueButtonRect = new Rect(2 * Screen.width / 3 + Screen.width / 9, 2 * Screen.height / 3 - Screen.height / 10  + Screen.height / 9, Screen.width / 10, Screen.width / 10);
         
         ArrowUp = new Triangle(DPadRect.center, new Vector2(DPadRect.xMin, DPadRect.yMin), new Vector2(DPadRect.xMax, DPadRect.yMin));
         ArrowDown = new Triangle(DPadRect.center, new Vector2(DPadRect.xMin, DPadRect.yMax), new Vector2(DPadRect.xMax, DPadRect.yMax));
         ArrowRight = new Triangle(DPadRect.center, new Vector2(DPadRect.xMax, DPadRect.yMin), new Vector2(DPadRect.xMax, DPadRect.yMax));
         ArrowLeft = new Triangle(DPadRect.center, new Vector2(DPadRect.xMin, DPadRect.yMin),new Vector2(DPadRect.xMin, DPadRect.yMax));
     }
 
     void OnGUI()
     {
         if (inputEnabled)
         {
             GUI.DrawTexture(DPadRect, DPad);
             GUI.DrawTexture(RedButtonRect, RedButton);
             GUI.DrawTexture(BlueButtonRect, BlueButton);
         }
     }
 
     void Update()
     {
         if (inputEnabled)
         {
             foreach (Touch touch in Input.touches)
             {
                 if (touch.phase == TouchPhase.Began && RedButtonRect.Contains(touch.position))
                 {
                     Debug.Log("Red Button Pressed");
                 }
 
                 else if (touch.phase == TouchPhase.Began && BlueButtonRect.Contains(touch.position))
                 {
                     Debug.Log("Blue button pressed");
                 }
 
                 else if ( (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Stationary) && DPadRect.Contains(touch.position)) 
                 {
                     Debug.Log("DPad touched");
 
                     if (ArrowUp.Contains(touch.position))
                     {
                         Debug.Log("Up arrow clicked");
                     }
                     else if (ArrowDown.Contains(touch.position))
                     {
                         Debug.Log("Down arrow clicked");
                     }
                     else if (ArrowRight.Contains(touch.position))
                     {
                         Debug.Log("Right arrow clicked");
                     }
 
                     else if (ArrowLeft.Contains(touch.position))
                     {
                         Debug.Log("Left arrow clicked");
                     }                    
                 }
             }
         }
     }
 
     public void EnableInput()
     {
         inputEnabled = true;
     }
 
     public void DisableInput()
     {
         inputEnabled = false;
     }
 }
 

The problem is that, using android studio's adb logcat, pressing the buttons does not generate any of the log messages. Moreover, it loops on the following lines:

 03-17 17:20:30.665  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.691  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.712  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.727  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.744  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.763  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.804  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.805  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.829  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.847  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.864  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.884  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.903  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.946  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.948  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.970  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:30.992  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:31.005  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:31.023  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:31.043  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:31.083  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:31.084  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:31.110  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:31.132  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:31.145  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)
 03-17 17:20:31.178  17478-17499/com.company.productname D/Unity﹕ Unknown event structure (0)

Any help would be appreciated. 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ukk · Mar 18, 2015 at 05:37 PM

The problem was that the GUI has a different coordinates system than the normal content, I had to add the following lines:

 Vector2 touchPosition = touch.position;
 touchPosition.y = Screen.height - touchPosition.y;

and use touchPosition instead of touch.position. Everything works fine now.

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

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

2 People are following this question.

avatar image avatar image

Related Questions

Keep getting AudioTrack messages when I use Android logcat with my unity app. 0 Answers

Android Options Menu 0 Answers

Is there a way to scroll GUI text WITHOUT scrollbars? 2 Answers

Unity 2d mobile android GUI texture button 1 Answer

Debug.Log print order, or Awake vs Start issue? 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