It works perfectly in the editor, but on Android it only sometimes registers an OnClick when I press it with my finger.
I’m on Unity 5.5.1f1
Is this a known issue?
I’ll post some videos of it if no-one has seen this before.
The scrollview is based on the default one from the Create\UI\scrollview menu
Ive added a vertical layout group to it, to which I add prefabs that contain buttons. These are the buttons that are not working.
The canvas is in front of the camera in worldspace and is scaled down to 0.02 in X and Y
VVVVVVVVVVV UPDATE VVVVVVVVVVVVV
I wrote my own workaround using 2D colliders instead of buttons
The colliders are registering hits just fine.
But when I wrote a class to not register hits if the scrollview moves, I get similar behaviour!
Heres the crude little workaround class I wrote…
public class ScrollButton : MonoBehaviour
{
public StoreItem Item;
bool FingerDownOnMe;
public void BeOnClicked()
{
VisualDebuggerRef.SetTxt("a store button" + " " + Random.Range(0, 10000));
FingerDownOnMe = true;
}
// This is called on all these objects whenever the scrollview moves
public void ScrollviewMoved()
{
FingerDownOnMe = false;
}
void Update()
{
// 'UppedthisFrame' will be true whenever any touchs phase == TouchPhase.Ended
if (Refs.man.Clickdetect.UppedthisFrame && FingerDownOnMe)
{
FingerDownOnMe = false;
Item.ButtonHit();
}
}
}
I’m guessing Unities UI classes work in a somewhat similar way to my workaround one. The problem is that the scrollview is registering as being moved when it should not be. This may be because of my test device which is an S7. Maybe the touch resolution is so high it is registering movement that is smaller than one pixel??
Also maybe the fact the the entire canvas has been scaled down could be affecting this? Say Unities classes have a distance threshold, if they are not taking into account scale then working on a scaled down canvas might make the distances they are using too big, so the threshold is reached too easily
Im going to add a distance limit to my workaround…
VVVVVVVVVVVVV UPDATE2 VVVVVVVVVVVVVVVV
This workaround code using colliders works perfectly…
public class ScrollButton : MonoBehaviour
{
const float scrollThreshold = 0.25f;
public StoreItem Item;
bool FingerDownOnMe;
Vector3 HitPos;
public void BeOnClicked()
{
//VisualDebuggerRef.SetTxt("a store button" + " " + Random.Range(0, 10000));
FingerDownOnMe = true;
HitPos = transform.position;
}
void Update()
{
// 'UppedthisFrame' will be true whenever any touchs phase == TouchPhase.Ended
if (Refs.man.Clickdetect.UppedthisFrame)
{
if (FingerDownOnMe && Mathf.Abs((transform.position - HitPos).y) < scrollThreshold) Item.ButtonHit();
FingerDownOnMe = false;
}
}
}
I’m going to report this issue as a bug to Unity