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 Paincho · Sep 09, 2014 at 02:53 AM · touchscreenpinball

Pinball using touchscreen

Hi I'm using a single script to trigger the flippers depending on where the touch is located on the screen on the x axis. If it's on the right side I trigger the right flipper and the left flipper on the left side. The left side works fine but when I put my finger on the right side of the screen the two flippers both left and right are triggered instead of just the right one. I can't figure out why so if anybody has an idea it would be greatly appreciated. Thanks.

             JointSpring L_spring = new JointSpring();
             L_spring.spring = L_flipperStrength;
             L_spring.damper = L_flipperDamper;
             JointSpring R_spring = new JointSpring();
             R_spring.spring = R_flipperStrength;
             R_spring.damper = R_flipperDamper;
 
             //FLIPPERS MOUSE
             if(Input.GetMouseButton(0)){
                 L_spring.targetPosition = L_pressedPosition;
             }else{
                 L_spring.targetPosition = L_restPosition;
             }
             if(Input.GetMouseButton(1)){
                 R_spring.targetPosition = R_pressedPosition;
             }else{
                 R_spring.targetPosition = R_restPosition;
             }
             
             //FLIPPERS TOUCH SCREEN
             foreach(Touch touch in Input.touches){
                 if(touch.position.x<posScreen){
                     if(touch.phase==TouchPhase.Began){
                         L_spring.targetPosition = L_pressedPosition;
                     }else{
                         if(touch.phase==TouchPhase.Stationary){
                             L_spring.targetPosition = L_pressedPosition;
                         }else{
                             if(touch.phase==TouchPhase.Ended){
                                 L_spring.targetPosition = L_restPosition;
                             }
                         }
                     }
                 }else{
                         if(touch.phase==TouchPhase.Began){
                             R_spring.targetPosition = R_pressedPosition;
                         }else{
                             if(touch.phase==TouchPhase.Stationary){
                                 R_spring.targetPosition = R_pressedPosition;
                             }else{
                                 if(touch.phase==TouchPhase.Ended){
                                     R_spring.targetPosition = R_restPosition;
                                 }
                             }
                         }
                 }
             }
             L_flipper.spring = L_spring;
             R_flipper.spring = R_spring;
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 WardPeeters · Apr 05, 2015 at 03:17 PM

Hello

I'm working on a pinball game too. This is the code I'm using for the flippers on mobile devices. Make sure you tick the boolean left paddle true for the left paddle(flipper).

 #pragma strict
 
 //Parameters
 var restPosition : float = 0F;
 var pressedPosition : float = 45F;
 var flipperStrength : float = 10F;
 var flipperDamper : float = 1F;
 var inputButtonName : String = "LeftPaddle";
 var isLeftPaddle : boolean = true;
 var paddleTouch : boolean = false;
 
 
 
 public function Awake ()
 {
     hingeJoint.useSpring = true;
 }
 
 // Update is called once per frame
 public function Update ()
 {
     paddleTouch = false;
     var touches : Touch[] = Input.touches;
     for (var touch : Touch in Input.touches) {
             //if (touch.position  && touch.phase != TouchPhase.Canceled)
             //Debug.Log(touch.position);
             if (isLeftPaddle && touch.position.x < 150){
                 paddleTouch = true;
             }
             else if (!isLeftPaddle && touch.position.x >= 150){
                 paddleTouch = true;
             } 
     }
     
     
     var spring : JointSpring = new JointSpring();
     
     spring.spring = flipperStrength;
     spring.damper = flipperDamper;
     
     if (Input.GetButton(inputButtonName) || paddleTouch){
         spring.targetPosition = pressedPosition;
 
         audio.Play();
         
     }else{
         spring.targetPosition = restPosition;
     }
     hingeJoint.spring = spring;
     hingeJoint.useLimits = true;
     hingeJoint.limits.min = restPosition;
     hingeJoint.limits.max = pressedPosition;
     
 }
Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Android unity, have the left side of the screen act as Fire1 and the right side act as Fire2. 3 Answers

storing the value in a temporary variable problem 1 Answer

How to do this GUI 2 Answers

multi toch GUI buttons 1 Answer

How can I make a GUI button be touch activated? 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