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 ironcore1 · Jul 26, 2013 at 08:48 AM · mobiletouchguitexturehittest

GUITexture HitTest touch area

Hi Everyone,

I’m trying to figure out what I’m doing wrong. I want to expand the a GUITexture.HitTest area so it’s easier to touch because the button is small (so it doesn't clutter up the screen space), has anyone else figured this out?

 var buttonB : GUITexture;
 
 function OnGUI(){
 
     buttonB.transform.position = Vector3 (0,0,-1);
     buttonB.transform.localScale =Vector3 (0,0,0);
     buttonB.pixelInset = Rect (0,Screen.height - buttonB.pixelInset.height - 6,    buttonB.pixelInset.width,buttonB.pixelInset.height);
 
 }
 
 function Update (){
     
     for(var touch : Touch in Input.touches)
     {
         if(touch.phase == TouchPhase.Began && buttonB.HitTest(Vector3(Screen.width - buttonB.pixelInset.width,Screen.height - buttonB.pixelInset.height,0)))
         {
             Debug.Log("The News");
         }
        }
 }

I just want to point out that touch.position works fine but again the touch area isn’t big enough...HELP PLEASE!

P.S This is for mobile so it needs a HitTest.

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 gregzo · Jul 26, 2013 at 08:58 AM

Hi ironcore1, A few things : 1)Why adjust the button's transform and pixelInset in OnGUI ? That will repeat the operation every frame, which surely isn't what you want.

2) Instead of using HitTest, you could create a new Rect that is bigger that the GUITexture and use Rect.Contains ( Vector2 touchPosition ) to check if the touch happened on your button.

3) Do yourself a favour and invest in a GUI framework - NGUI is the most widely used out there. Unity's GUI is cumbersome and inefficient, and will soon be completely overhauled by NGUI's developper so you might as well start learning his way of doing things.

All the best!

Comment
Add comment · Show 2 · 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 ironcore1 · Jul 26, 2013 at 09:09 AM 0
Share

Hi gregzo,

Thanks for your fast feedback and I am looking into GUI Frameworks but for now I need this to be a prototype and inexpensive as possible. Once the concept is down I plan on investing in NGUI as I have heard good things about it.

For the time being I will use your Rect solution and I really appreciate your help.

Take it easy and thanks again! ;)

avatar image gregzo ironcore1 · Jul 26, 2013 at 09:10 AM 0
Share

Hi ironcore1, Do accept the answer, and comment as a comment not a new answer, helps keeping things clean! Glad I could help, Gregzo

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

15 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 avatar image avatar image avatar image

Related Questions

Touch gui texture buggy 0 Answers

How to stop second finger from manipulating position of gui joystick 1 Answer

GUITexture Active and Enabled=false but still ı can click 1 Answer

Multi touches problem 0 Answers

Gui , Message , Text, Touch and Question ? 2 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