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 LANDO · Jul 17, 2012 at 04:59 AM · iosinputguitextureactiveenabled

iOS GUITexture not enabled still receives input

I'm using GUITextures for my buttons in an iOS app. They seem to function well (when tapped they do something) however I don't want them enabled or visible until the user taps the appropriate button to make them appear.

As of now I have a "color" button which when tapped makes a color picker appear for the user to select the desired color they would like to change on a given gameObject. The problem is in Start() I make the gameObject.active = false and each component.enabled = false which makes the GUITexture not visible however it still functions when the it's area is tapped.

Should I just instantiate the empty gameObject with the GUITexture component to avoid this? I would think there is a way for the gameObject to just be disables/not active however it is not working for me..

Here's the GUI script I'm using to detect touch and call to other scripts' functions..

 var color : GUITexture; //empty gameObject with GUITexture component
 var cp : GameObject; //ColorPicker gameObject with GUITexture and script components
 
 function Start() {
 
 cp.gameObject.active = false;
 cp.GetComponent(colorPickerTest).enabled = false;
 cp.GetComponent(GUITexture).enabled = false; 
 
 }
 
 function Update () {
 
     var fingerCount = 0;
     for (var touch : Touch in Input.touches) {
         if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
             fingerCount++;
     }
     if (fingerCount > 0) {
         print ("User has " + fingerCount + " finger(s) touching the screen");
         }
         
    if (Input.touchCount>0)
    {
       for (var touch : Touch in Input.touches)
       {
         if(touch.phase == TouchPhase.Began && color.HitTest(touch.position))
          {
            cp.gameObject.active = true;
            cp.GetComponent(colorPickerTest).enabled = true;
            cp.GetComponent(GUITexture).enabled = true;
      Debug.Log("TouchedColorBtn");  
          }
 
  if(touch.phase == TouchPhase.Began && cs.GetComponent(GUITexture).HitTest(touch.position))
          { 
           cs.GetComponent(ColorSwitch).colorPick();
           Debug.Log("TouchColorPicker"); 
          }
     }
     }
     }
          
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
1
Best Answer

Answer by Seth-Bergman · Jul 19, 2012 at 07:17 AM

you could just use a flag instead:

 for (var touch : Touch in Input.touches)
       {
         if(touch.phase == TouchPhase.Began && color.HitTest(touch.position))
          {
            enablePicker = true;
      Debug.Log("TouchedColorBtn");  
          }
 
  if(touch.phase == TouchPhase.Began && cs.GetComponent(GUITexture).HitTest(touch.position) && enablePicker)
          { 
           cs.GetComponent(ColorSwitch).colorPick();
           Debug.Log("TouchColorPicker"); 
          }
     }
Comment
Add comment · Show 4 · 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 LANDO · Sep 16, 2012 at 09:20 AM 0
Share

I don't understand how this is using a flag, is it "enablePicker = true;" ?

avatar image Seth-Bergman · Sep 17, 2012 at 02:52 AM 0
Share

yes that's what I meant, I could have said "boolean"

avatar image LANDO · Sep 17, 2012 at 10:40 AM 0
Share

A boolean seems like it would work, however I've tried it along with disabling the GameObject with GameObject.enabled = false; or GameObject.component.enabled = false; or GameObject.SetActiveRecursively(true);

Although the GUITexture is not drawn, the GameObject with the GUITexture component is not active and yet it still is detecting taps with HitTest and functions are being called from scripts attached to the deactivated GameObject.... I'm kinda stumped here.

avatar image LANDO · Sep 17, 2012 at 10:47 AM 0
Share

After writing all of that... I think I just fixed it. Ins$$anonymous$$d of just using:

if(touch.phase == TouchPhase.Began && cp.GetComponent(GUITexture).HitTest(touch.position)) {
//DoSomething
}

I added that the boolean must be set to true along with the HitTest:

if(touch.phase == TouchPhase.Began && enabledPicker == true && cp.GetComponent(GUITexture).HitTest(touch.position)) {
//DoSomething
}

This seems to be working for now.. I'll keep testing it out... Thanks again for all of your help!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

.enabled does not enabled GUItexture 1 Answer

Best way to get to get touch inputs? 1 Answer

How to fix this problem? ios touch screen? 1 Answer

How to change button sizes depending on iOS device? 1 Answer

How to get sensor(e.g. accelerometer) input from external device(phone and similar) to PC Unity editor? 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