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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by SunnyDayWarrior · Jun 10, 2013 at 08:24 PM · iosiphonetouchdrag

How do i make a continuos touch that triggers more then one "button"?

Hello Unity Community! I am a beginner making my first game on unity, i have searched for a solution and could not find one in the forums, i put my trust in you...

I am trying to stack a few buttons (around 10) vertically one on top of the other to create a sort of a scale for sounds. the problem is i need it to activate more then one button with one continuous touch... in other words: i would like to touch the screen and drag my finger across the 10 buttons, and have them all pressed... currently with a continuos touch, it only recognizes the first button i touched...

i am aware i could have approached this from the wrong angle, so i include my touch_logic script:

using UnityEngine; using System.Collections;

public class TouchButtonLogic : MonoBehaviour {

 void Update () 
 {
     //check for touch
     if(Input.touches.Length <= 0)
     {
         //if no touches detected
     }
     
     else //if there is a touch
     {
         for(int i=0; i
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 Owen-Reynolds · Jun 10, 2013 at 09:28 PM

You chopped off your code, but, "slide over counts as click" is easy.

Typical button code keys off of GetMouseUp or phase=TouchPhase.end. Simply change to not checking for that stuff. Each frame check MousePosition or Input.Touch[i].position and press that button. Then have TouchPhase.end unpress them all.

Comment
Add comment · Show 3 · 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 SunnyDayWarrior · Jun 12, 2013 at 10:16 AM 0
Share
 void Update () 
     {
         //check for touch
         if(Input.touches.Length <= 0)
         {
             //if no touches detected
         }
         
         else //if there is a touch
         {
             for(int i=0; i<Input.touchCount; i++) //loop through touches on screen
             {
                 if(this.guiTexture.HitTest(Input.GetTouch(i).position))//execute for current touch
                 {
                     //if current touch hits our button, run this code
                     
                     if(Input.GetTouch(i).phase==TouchPhase.Began)
                     {
                         print ("the touch has began " + this.name);
                         audio.Play();
                     }
                     
                     if(Input.GetTouch(i).phase==TouchPhase.Ended)
                     {
                         print ("the touch has ended " + this.name);
                         audio.Stop();
                     }
                     
                     
                 }
             }
         }
     }
 
     
 }
avatar image SunnyDayWarrior · Jun 12, 2013 at 10:18 AM 0
Share

i still want the sound to stop when my finger is not on the button, but i dont want to lift it from the screen either... i tried replacing the for loop, but it still did not work as i expected, any ideas?

avatar image Owen-Reynolds · Jun 12, 2013 at 01:44 PM 0
Share

Easier to do this assu$$anonymous$$g only a single touch. You can add multiples later. Otherwise, same advice.

Don't check for TouchPhase.Began, since you don't care if they just now tapped the button, or tapped somewhere else and slid onto the button. Likewise don't check for end, since all you care about is the finger was on the button before and now it isn't.

For turning off, you might save the single button that was turned on last frame. If the finger isn't over it this frame, turn off.

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

16 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

Related Questions

Multiple Touch Drag iOS 0 Answers

Tap to Move Drag to Look Null Reference 1 Answer

Touch and drag an object 0 Answers

Click Drag not working on iphone 2 Answers

TouchPhase.Stationary lags on iOS 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