Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by Triqy · Oct 01, 2011 at 04:40 PM · androidtouchbuttonsguitexture

GUITexture Button Help, Android touch

I have a GUITexture button im trying to get working from a mobile app im working on for android. Im trying to be able to touch the button have it display "TOUCHED" in the Debug.Log. The Problem is that when i touch the GUITexture button, the only place that it registers the touch is in the top right corner of the GUITexture Button. This is the code i have so far:

 private var gui : GUITexture;
 
 private var defaultRect : Rect;
 
 private var guiTouchOffset : Vector2;
 
 
 
 function Start(){
 
 gui = GetComponent( GUITexture );
 
 
 
 // get where the gui texture was originally placed
 
 defaultRect = gui.pixelInset;
 
 
 
 // get our offset for center instead of corner
 
 guiTouchOffset.x = defaultRect.width;
 
 guiTouchOffset.y = defaultRect.height;
 
 }
 
 
 
 
 
 function Update(){
 
 
 
 var count = Input.touchCount;
 
 
 
 // account for the offset in our calculations
 
 
 
 for (var i: int = 0; i < count; i++){
 
 
 
 var touch : Touch = Input.GetTouch(i);
 
 
 
 var guiTouchPos : Vector2 = touch.position - guiTouchOffset;
 
 
 
 if (gui.HitTest( touch.position )){
 
 Debug.Log("Touched");
 
 gui.pixelInset.x = guiTouchPos.x;
 
 gui.pixelInset.y = guiTouchPos.y;
 
 }
 
 }
 
 }

any help Is greatly appreciated. This thing has been troubling me for the longest time now. Thanks

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
1
Best Answer

Answer by Triqy · Oct 01, 2011 at 06:04 PM

Never mind. I answered my own question. Here is two ways to do it:

  • > function Update() > > { > > for (var touch : Touch in > Input.touches) > > { > > if (guiTexture.HitTest > (touch.position)) >

     >   {
       > 
       >     // we are now in the guitexture
       > 
       >     Debug.Log("Touch"); 
       > 
       >    
       > 
       >   }
       > 
       >  }
       > 
       > }
    
    

      private var gui : GUITexture;
    
      function Start(){
    
      gui = GetComponent( GUITexture );
    
      var newInset : Rect = new Rect(0,350,134,40);
    
      guiTexture.pixelInset = newInset;
    
      }
    
      function Update(){
    
      if(Input.touchCount > 0){
    
      for(var i : int = 0; i < Input.touchCount; i++){
    
      var touch : Touch = Input.GetTouch(i);
    
      if(touch.phase == TouchPhase.Began &&
    

    guiTexture.HitTest(touch.position)){

      Debug.Log("logged");
    
      }
    
      }
    
      }
    
      }
    
    


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
0

Answer by Triqy · Mar 22, 2013 at 05:58 AM

This is a cleaner and more understandable answer!

http://answers.unity3d.com/questions/422187/android-guitexture-touch.html

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

Detect touch on a specific GUITexture 3 Answers

GUITexture and Touch Input 1 Answer

Touch Button for 4 animation 2 Answers

Buttons and Touch area issue on android 0 Answers

Android touch latency vs. audio playback 0 Answers


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