Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to add touch control to Windows Phone game?

Discussion in 'Scripting' started by GustavoH, Nov 14, 2013.

  1. GustavoH

    GustavoH

    Joined:
    Sep 29, 2013
    Posts:
    116
    Did anyone already had this experience?
     
  2. GustavoH

    GustavoH

    Joined:
    Sep 29, 2013
    Posts:
    116
    Do i have to use plugin?
     
  3. ttww

    ttww

    Joined:
    Nov 9, 2013
    Posts:
    5
    What is Your problem exactly? You can use Input.GetTouch or even Input.GetKey(KeyCode.Mouse0) // Input.mousePosition without any problem, since by default touch is also interpreted as a mouse.
     
  4. GustavoH

    GustavoH

    Joined:
    Sep 29, 2013
    Posts:
    116
    Well, i used this code but doesn't Works on Windows Phone:

    Code (csharp):
    1. if (Input.touchCount > 0  Input.GetTouch(0).phase == TouchPhase.Moved) {
    2.   Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
    3.   transform.Rotate(0, touchDeltaPosition.y * rotateSpeed, 0);
    4.  
    5.    }
    6.  
    7.  
     
  5. Gord10

    Gord10

    Joined:
    Mar 27, 2013
    Posts:
    142
    I failed to see anything wrong with the touch code itself, I've got an almost identical code that works fine in Windows Phone.

    Are you sure that your code ever successfully reaches the if statement? When I make mobile games, I print the problematic values on the screen as a GUI text, so I can be sure that Input.touchCount and Input.GetTouch(0).phase are really correct or not.
     
  6. GustavoH

    GustavoH

    Joined:
    Sep 29, 2013
    Posts:
    116
    Do you have the code snippets to post?

    Maybe a detail i forgot to add.
     
  7. Gord10

    Gord10

    Joined:
    Mar 27, 2013
    Posts:
    142
    Code (csharp):
    1.     bool ProcessPinchZoom()
    2.     {
    3.          if (Input.touchCount == 2  Input.GetTouch(0).phase == TouchPhase.Moved  Input.GetTouch(1).phase == TouchPhase.Moved)
    4.          {
    5.             Vector2 curDist = Input.GetTouch(0).position - Input.GetTouch(1).position; //current distance between finger touches
    6.             Vector2 prevDist = ((Input.GetTouch(0).position - Input.GetTouch(0).deltaPosition) - (Input.GetTouch(1).position - Input.GetTouch(1).deltaPosition)); //difference in previous locations using delta positions
    7. ....
    8.  
    The reason why there are two touches here is simply because it's a pinching script, that's an unimportant detail here.
     
  8. GustavoH

    GustavoH

    Joined:
    Sep 29, 2013
    Posts:
    116
    My code doesn't have bool. What's the importance to have?
     
  9. ManAmazin

    ManAmazin

    Joined:
    Aug 7, 2013
    Posts:
    246
    What is it doing instead of activating this code? have you setup a debug.log in your code to show whats going on? as Gord10 said i dont see anything wrong with your code at glance so there something not wired up right maybe.
     
  10. GustavoH

    GustavoH

    Joined:
    Sep 29, 2013
    Posts:
    116
    The debug log isn't reporting anything wrong.

    I made a few changes:

    Code (csharp):
    1. if (Input.touchCount > 0  Input.GetTouch(0).phase == TouchPhase.Moved) {
    2.             Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
    3.             transform.Rotate(0, touchDeltaPosition.x * rotateSpeed, 0);
    4.  }
    To:

    Code (csharp):
    1. if (Input.touchCount > 0  Input.GetTouch(0).phase == TouchPhase.Moved)
    2.      {
    3.         Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
    4.         transform.eulerAngles = new Vector3(0, touchDeltaPosition.x * rotateSpeed, 0);
    5.      }
    Let's see if does it Works.
     
  11. Gord10

    Gord10

    Joined:
    Mar 27, 2013
    Posts:
    142
    That bool part is nothing about our topic. It's just the part of the code I used in my game, that's irrelevant to how Input works.

    Does your debug logs show that you can actually reach the if block?