Problem with Virtual Joystick Touch input [C#]

Hello guys, I’ve got a problem with my script that implements a virtual joystick on screen (for now i’m testing it only in android).

My VirtualJoystick script: using UnityEngine;using UnityEngine.UI;using UnityEngine.EventSystems;us - Pastebin.com

I have taken that script from this video if you want to understand the implementation:

Ball moving script: using System;using UnityEngine;using System.Collections;namespace UnityS - Pastebin.com

The script works well and it does the job. The fact is that I don’t want a static joystick (in the video he puts it in the bottom right of the canvas), but I want that the joystick updates its position where my finger touches.

I tried to create a script which check if player touches the screen with one finger, and if it does, enables the joystick object at the touch position: using UnityEngine;public class CheckTouchForJoystick : MonoBehaviour{ - Pastebin.com

I had to put it as a component of the Canvas, otherwise, if i try to create a new area smaller than the canvas and put this script on it to limit the zone where you can spawn the joystick, touch is not recognized (don’t know why, maybe you can help me achieveing this).

There are some bugs in this script:

1- The problem with that is that every button inside the canvas now doesn’t work anymore and, also, I don’t want that every single pixel of the phone can be recognized as an input area to activate the joystick. As I said, I want that the joystick should activate just in a limited portion of the canvas. How can I achieve that and how can i solve the button problem?

2- I have to touch at the same position 2 times to activate the movement of the joystick, otherwise, with one single touch, the joystick spawns but the analog doesn’t move.

Thank you in advance!

PS: is there a way to debug a script where I use the Input class inside the editor? For now, I’m always building and running it to the phone, because in the editor, touches without using OnPointerDown are not recognized.

I have a dynamic virtual joystick in my proximity buttons project. It’s called a VAButton and there is sample code to use it.

https://bitbucket.org/kurtdekker/proximity_buttons

Wherever your finger goes down is the zero, and output is relative to that. There’s some filtering and clipping available too, optionally. You can sprinkle as many of those joysticks onscreen as you want, as long as the rectangles don’t overlap. It makes a twinstick touchscreen shooter really easy to do.

And I’m free to use it even if it is a commercial project?

It is BSD-licensed. There’s plenty of FAQs out there to guide you. https://en.wikipedia.org/wiki/BSD_licenses