Hello Guest

Author Topic: tk2dButton clicks doesn't work on Unity4.2 beta  (Read 13234 times)

nemoryoliver

  • Newbie
  • *
  • Posts: 10
    • View Profile
tk2dButton clicks doesn't work on Unity4.2 beta
« on: May 15, 2013, 03:50:47 am »
I can confirm this is the line that doesn't get called:

Code: [Select]
            if (Input.GetMouseButtonDown(0))
            {
                Debug.Log("Casting Ray");

                Ray ray = viewCamera.ScreenPointToRay(Input.mousePosition);
                RaycastHit hitInfo;

                if (collider.Raycast(ray, out hitInfo, 1.0e8f))
                {
                    if (!Physics.Raycast(ray, hitInfo.distance - 0.01f))
                        StartCoroutine(coHandleButtonPress(-1));
                }
            }

nemoryoliver

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #1 on: May 15, 2013, 04:46:19 am »
Lucky I found how to fix the issue.

tk2dButton.cs


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #2 on: May 15, 2013, 09:48:38 am »
Really? Thats terrible :(
That value is the length of the ray. Can you please try it with Mathf.Infinity instead of 100? (Don't have the beta installed due to checking another bug elsewhere...)

nemoryoliver

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #3 on: May 15, 2013, 11:59:42 am »
I also have to move out to the block that if statement. because the Else statement is not entered. This problem is only in the Editor though. no problem with the device.

nemoryoliver

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #4 on: May 15, 2013, 01:10:09 pm »
Here's the Unity4.2 b2   removed link

I am not sure if you will be able to download it.
« Last Edit: May 15, 2013, 01:25:54 pm by unikronsoftware »

nemoryoliver

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #5 on: May 15, 2013, 01:20:28 pm »
Mathf.Infinity works. :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #6 on: May 15, 2013, 01:26:26 pm »
Hi I removed that link you shared - its private :)
Yes, I've got access to it - just haven't had the time to install and test in it.

Glad math.infinity works though.

nemoryoliver

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #7 on: May 15, 2013, 01:37:47 pm »
Sorry for posting the link. And it's nice you got 4.2. Let me know when you got the same issue and if you got a different way to fix. thanks. :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #8 on: May 15, 2013, 01:45:31 pm »
No, that is probably the correct thing to do - though it looks like they have introduced a bug. Mathf.Infinity > 1.0e8, so I dont know why its not working. I think there were a few more people complaining about broken physics in the beta forum...

nemoryoliver

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #9 on: May 15, 2013, 01:57:22 pm »
Oh. But there's a bug to the new Editor right? Anyway it works now. :) Thanks man,

Mixu

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #10 on: July 23, 2013, 12:11:12 am »
Hi!

I just bought 2D Toolkit, and updated to Unity 4.2, and tk2dButton doesn't work :(

In the editor when clicking Play on the "6 - button and 3d sprites" demo, if I click any button it doesn't work.
As I have seen in the code, my clicks go through here:

Code: [Select]
#if !UNITY_FLASH
if (Input.multiTouchEnabled)
{
for (int i = 0; i < Input.touchCount; ++i)
{
Debug.Log("bucle "+i);

But never gets to the Log command, so there's multiTouch, but no touchCount when clicked.
I'm using Windows 7, and as I'm aware of... I don't have any multi touch device.

Edit:
I set

#if !UNITY_FLASH && false

and now it works perfectly.
Strange, isn't it? :/
« Last Edit: July 23, 2013, 12:13:46 am by Mixu »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #11 on: July 23, 2013, 12:19:51 am »
What build platform have you got set?

ahtram

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #12 on: July 23, 2013, 07:39:07 am »
Same problem here.
I set my project in Android platform and using Unity under a windows 8 machine.

Mixu

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #13 on: July 23, 2013, 08:27:17 am »
What build platform have you got set?
I had MacOSX and changed to Windows and x64, but the button still didn't work.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButton clicks doesn't work on Unity4.2 beta
« Reply #14 on: July 23, 2013, 10:47:21 am »
After a bit of investigation, it looks like Unity has decided to change how Input.multiTouchEnabled works.
It now returns true on everything I've tried it on, even my macbook which clearly doesn't have a multitouch display.

Using this makes it work:
Code: [Select]
bool resolvedHit = false;

#if !UNITY_FLASH
if (Input.multiTouchEnabled)
{
for (int i = 0; i < Input.touchCount; ++i)
{
Touch touch = Input.GetTouch(i);
if (touch.phase != TouchPhase.Began) continue;
            Ray ray = viewCamera.ScreenPointToRay(touch.position);
            RaycastHit hitInfo;
            if (collider.Raycast(ray, out hitInfo, 1.0e8f))
            {
if (!Physics.Raycast(ray, hitInfo.distance - 0.01f))
{
StartCoroutine(coHandleButtonPress(touch.fingerId));
resolvedHit = true;
break; // only one finger on a buton, please.
}
            }            
}
}
#endif

if (!resolvedHit)
{
if (Input.GetMouseButtonDown(0))
        {
            Ray ray = viewCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo;
            if (collider.Raycast(ray, out hitInfo, 1.0e8f))
            {
if (!Physics.Raycast(ray, hitInfo.distance - 0.01f))
StartCoroutine(coHandleButtonPress(-1));
            }
        }
}


In any case, I strongly recommend using the tk2dUIButton - its far more efficient to use and much more customizable, and this thing has been more or less deprecated (reminds me I need to replace them in the demos). Check out the tk2dUI demo.