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 nobleGas · Jan 17, 2014 at 03:41 PM · touchdebugmultiple objects

GUITexture multiple component activation

Hi guys,

I basically have a certain number of GUITextures in my scene and i want to be able to scroll through each one seperately. Generally what will happen is; the player will start off with GUITexture1 and when they press either a left or right button, they should go to a previous or next GUITexture.

So TLDR; i want to scroll through multiple GUITextures by enable/disable but at the moment it goes through to my second GUITexture(notes2) and then quickly onto 3. How do i get it to stay on 2?

Here is what i have tried so far:

     if (rightButton.tapCount>0&&noteSwitch == NoteSwitch.Notes1)
     {
         noteSwitch = NoteSwitch.Notes2;
     }
     else if (rightButton.tapCount>0&&noteSwitch == NoteSwitch.Notes2)
     {
         noteSwitch = NoteSwitch.Notes3;
     }
     if (leftButton.tapCount >0&&noteSwitch == NoteSwitch.Notes3)
     {
         noteSwitch = NoteSwitch.Notes2;
     }
     else if (leftButton.tapCount >0&&noteSwitch == NoteSwitch.Notes2)
     {
         noteSwitch = NoteSwitch.Notes1;
     }
Comment
Add comment · Show 3
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 nobleGas · Jan 18, 2014 at 08:18 PM 0
Share

I should update.

So i tried it with an array and funnily enough the same problem occurs. Starts with note 1 and shows 2 for a brief split second and goes to 3.

What i'll do is break down my hierarchy, game objects and the main script i have putting it all together. If anyone could chime in, i would be grateful.

alt text

So basically in this scene; what i want to achieve is a controlling a set of GUITextures with some basic Buttons i have created.

The 4 buttons do the following:

Up and Down scroll up and down on the GUITextures(Notes1,2 and 3). Left and Right are meant to select a GUITexture and put it on display. A basic previous/Next Button.

$$anonymous$$y Notes$$anonymous$$anager will be handling and putting to action what i describe above.

I have a script running on the buttons that handles touch and i use tapCount on each to get a reading for which one is being pressed.

Here is my main Script i have attached on Notes$$anonymous$$anager:

 public class TouchGUINotes : $$anonymous$$onoBehaviour
 {
 
   
     //The buttons we'll be using to flip through the notepad
     public $$anonymous$$PJoystick upButton;
     public $$anonymous$$PJoystick downButton;
     public $$anonymous$$PJoystick rightButton;
     public $$anonymous$$PJoystick leftButton;
 
     //We'll use this to transform the GUITexture.
     private Rect pixelinset;
     private Rect pixelinset2;
     private Rect pixelinset3;
 
     //Array for the notes + a current note that will be used to display the current note.
     public GUITexture[] notepad;
     private GUITexture currentNote;
 
     //index for the array.
     private int index = 0;
 
 
 // Update is called once per frame
     void Update ()
     {
 
         #region scroll notes
         //Unless the note is being displayed, through current note, do not enable.
         foreach (var note in notepad)
         {
             note.enabled = false;
         }
 
         //Scroll Controls.
         if (upButton.tapCount > 0)
         {
             pixelinset = currentNote.pixelInset;
             pixelinset.y += new Vector2(0, 5).y;
             currentNote.pixelInset = pixelinset;
         }
 
         if (downButton.tapCount > 0)
         {
             pixelinset = currentNote.pixelInset;
             pixelinset.y += -new Vector2(0, 5).y;
             currentNote.pixelInset = pixelinset;
         }
 
         #endregion
 
       
         //Controls to change GUITexture
         if (rightButton.tapCount >= 1)
         {
             index++;
             
         }
 
 
         if (leftButton.tapCount >= 1)
         {
             index--; 
         }
 
         index = $$anonymous$$athf.Clamp(index, 0, notepad.Length - 1);
         currentNote = notepad[index];
         currentNote.enabled = true;
 
     }
 
 
 
    
 }
 
 
hirerarchy view.png (4.8 kB)
avatar image robertbu · Jan 18, 2014 at 08:26 PM 0
Share

@nobleGas - I don't know the $$anonymous$$PJoystic class, you need to check out how it is processing the tap count. Between line 38 and 39, and between line 44 and 45, insert the following code:

 Debug.Log(Time.frameCount);

If you get more than one value per click, then you know this is the heart of your issue. If you don't, you can rule out that as an issue

avatar image nobleGas · Jan 18, 2014 at 08:52 PM 0
Share

Okay i think i see the problem here. Time.frameCount shows that it is being pressed more than once, like 200/300 times the amount.

I've removed $$anonymous$$PJoystick and put a much simpler script that counts an Int if it detects a touch on the function On$$anonymous$$ouseDown().

 public class TouchButton : $$anonymous$$onoBehaviour
 {
 
 
     public int touchCount;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if (touchCount==1)
         {
             touchCount = 0;
         }
     }
 
     void On$$anonymous$$ouseDown()
     {
         touchCount++;
     }


This allows me to display the right GUITexture but my issue is that the framecount is still high, im getting upwards 1000. The other issue is that the Up and Down scroll buttons now make the game freeze.

Thanks for all your help so far.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Jan 17, 2014 at 04:29 PM

You need to put some 'else' clauses in your code.

 if (rightButton.tapCount>0&&noteSwitch == NoteSwitch.Notes1)
 {
     noteSwitch = NoteSwitch.Notes2;
 }
 else if (rightButton.tapCount > 0 && noteSwitch == NoteSwitch.Notes2)
 {
     noteSwitch = NoteSwitch.Notes3;
 }
 if (leftButton.tapCount > 0 && noteSwitch == NoteSwitch.Notes3)
 {
     noteSwitch = NoteSwitch.Notes2;
 }
 else if (leftButton.tapCount > 0 && noteSwitch == NoteSwitch.Notes2)
 {
     noteSwitch = NoteSwitch.Notes1;
 }

Note this kind of behavior is easier handled by using an array rather that state and somewhat complex 'if' statements.

Comment
Add comment · Show 7 · 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 nobleGas · Jan 17, 2014 at 04:34 PM 0
Share

Thanks for the reply.

I just put in the else if statements, still doing the same thing. How would i do it with an array? Go through each variable with a foreach statement?

avatar image robertbu · Jan 17, 2014 at 04:59 PM 0
Share

For your current code is rightButton.tapCount true only for the current frame?

avatar image robertbu · Jan 17, 2014 at 05:05 PM 0
Share

You are not calling this from inside OnGUI() are you? OnGUI() gets called multiple times per frame.

avatar image robertbu · Jan 17, 2014 at 05:08 PM 0
Share

As for an array, if you textures were in an array, you would just manipulate the index to the array. Something like:

 if (rightButton.tapCount > 0)
     index++;
 if (leftButton.tapCount > 0)
     index--;
 
 index = $$anonymous$$athf.Clamp(index, 0, lengthOfArray-1);

Then index would be used when you display the texture to pick the correct texture.

avatar image nobleGas · Jan 17, 2014 at 05:47 PM 0
Share

Im calling rightbutton.tapcount from inside update. I tried it from inside fixedUpdate and LateUpdate, and the same issue occurs. Im currently trying the array idea.

Im just running into a few problems, first of all; what is index? Is it an int? Here is what im trying :

 public GUITexture[] notepad;
 
 if (rightButton.tapCount > 0)
     notepad++;
 if (leftButton.tapCount > 0)
     notepad--;

I know im doing something wrong but not sure which way up to try arrays.

Show more comments

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

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

Related Questions

Augmented reality - LeanTouch/Lean Touch - What to do with multiple objects & how to reset position 1 Answer

iOS touch triggers the wrong object 0 Answers

Debug iPhone game without smartphone. 1 Answer

Processes two touches instead of one 0 Answers

What is the protocol Accepted by TUIO Input for asset Touchscript? 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