Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 thesinickdios · Sep 07, 2018 at 04:44 AM · inputtouchcollidersclickswipe

How add click area?

hi, im making a project and you need to throw a ball with swipe but my code have a touch phase so when i click in pause menu my code detects like im touching the ball and the ball drops, i have another code and i make a ball click area with a collider so you need to touch in the collider to shoot i want make the same but with this code, i tried with the same forms with collider but doesnt work.

   if ( Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
         {
 
             // getting touch position and marking time when you touch the screen
             touchTimeStart = Time.time;
             startPos = Input.GetTouch(0).position;
         }
 
         // if you release your finger
         if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended && throwAllowed)
         {
 
             // marking time when you release it
             touchTimeFinish = Time.time;
 
             // calculate swipe time interval 
             timeInterval = touchTimeFinish - touchTimeStart;
 
             // getting release finger position
             endPos = Input.GetTouch(0).position;
 
             // calculating swipe direction
             direction = startPos - endPos;
 
             // add force to ball rigidbody depending on swipe time and direction
             rb.isKinematic = false;
             rb.AddForce(-direction / timeInterval * throwForse);
             // one attempt to throw a ball only
             throwAllowed = false;
 
         }
Comment
Add comment · Show 1
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 Piyush_Pandey · Sep 07, 2018 at 06:31 AM 0
Share

If i understood you right then you want your collider NOT to take touches when in pause mode right?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by tormentoarmagedoom · Sep 07, 2018 at 06:59 AM

You can simply make a boll variable called "pause" and activate it when you are in pause.

The at the touch detection code, just commence with a

 if (!pause).....

Bye

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 thesinickdios · Sep 07, 2018 at 08:14 PM 0
Share

@tormentoarmagedoom i tried that but doesnt work i put a bool variable ballClicked and if touch collider the ballClicked is true and if is true dont do anything

avatar image thesinickdios thesinickdios · Sep 07, 2018 at 08:15 PM 0
Share
  RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
 
         if (hit.collider != null)
         {                  
             if (hit.collider.gameObject.name == ballClick.gameObject.name)
             {   
                 ballIsClicked = true;                                          
             }
             else
             {                                                         
                 ballIsClicked = false;                                          //Don't start activating the shot
             }
         }
        
    
         if ( Input.touchCount > 0 && ballIsClicked == false && Input.GetTouch(0).phase == TouchPhase.Began)
         {
 
             // getting touch position and marking time when you touch the screen
             touchTimeStart = Time.time;
             startPos = Input.GetTouch(0).position;
         }

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

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

Related Questions

Input.getTouch() vs checking if button is clicked 1 Answer

Detect swipe along 3d arrows 1 Answer

mouse input to touch input help please 0 Answers

swipe movement control 1 Answer

How to disable Touch to Mouse Click translation 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