Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming touch on non-touch supported computer in unity

I have a touch screen laptop (Lenovo IdeaPad Flex 15, Windows 10) but on Unity, if I run the code:

    if (Input.touchSupported)
        print("supported");
    else
        print("not supported");

It prints that it is not supported. I am trying to make Pong, but you control both paddles and try to get a high score. Here is the code for trying to work past the fact that no touches are ever seen as touches. The code is supposed to move the paddle up or down.

      if (Input.GetMouseButton(0)) {
        if (Input.mousePosition.x < Screen.width / 2)
        {
            //Begin Section: Touch left side
            if (mousePos.y > transform.position.y)
            {
                yPos = gameObject.transform.position.y + (paddleSpeed * Time.deltaTime);
            }
            else
            {
                yPos = gameObject.transform.position.y - (paddleSpeed * Time.deltaTime);
            }
            //End of section
        }

    }

This works, the only problem is, the paddles have to move independently of each other. So I programmed the other paddle the same way. But, when I run the program and touch my screen with both fingers, the paddles freak out and don't work.

Question: I need a way to program touch support for both paddles. This can be answered in two ways: Either telling me how to program around not having touch support, or how to get Unity to realize I do have touch support

Any help with this would be hugely appreciated! Thanks!

Update: I forgot to add that I already tested the above code on my Android and it freaks out when you use two hands, otherwise it is flawless.

like image 257
Pookie Avatar asked Jun 20 '26 11:06

Pookie


1 Answers

You could also download Unity Remote 4 for your Mobile phone. It really helped me a lot : http://docs.unity3d.com/Manual/UnityRemote4.html

edit:

  1. Download & install Unity Remote 4 on your device.
  2. Enable USB debugging on your device and connect it to your pc.
  3. Start Unity Remote 4 and then restart Unity.
  4. In Unity, navigate to: Edit -> Project Settings -> Editor.
  5. In the Inspector, you can select now under "Unity remote' your device.
  6. Hit the Play Button in Unity.
like image 180
Doee Avatar answered Jun 22 '26 01:06

Doee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!