2D Toolkit Forum

2D Toolkit => Support => Topic started by: nemoryoliver on May 15, 2013, 03:50:47 am

Title: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: nemoryoliver 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));
                }
            }
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: nemoryoliver on May 15, 2013, 04:46:19 am
Lucky I found how to fix the issue.

tk2dButton.cs

(http://i.imgur.com/0Ow8MjQ.jpg)
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: unikronsoftware 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...)
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: nemoryoliver 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.
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: nemoryoliver 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.
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: nemoryoliver on May 15, 2013, 01:20:28 pm
Mathf.Infinity works. :)
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: unikronsoftware 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.
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: nemoryoliver 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. :)
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: unikronsoftware 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...
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: nemoryoliver 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,
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: Mixu 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? :/
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: unikronsoftware on July 23, 2013, 12:19:51 am
What build platform have you got set?
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: ahtram 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.
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: Mixu 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.
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: unikronsoftware 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.
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: Mixu on July 23, 2013, 11:15:26 am
Thanks! :)
I suppose that using the tk2dUIButton inside the games, as if the object is not a button would work fine.
I have put some things in the screen that you can interact with them, for example... when you click it animates and plays a sound, or sends a signal (I have done it in SDL in C++, and I'm porting it to Unity).
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: unikronsoftware on July 23, 2013, 11:19:01 am
Yup it would work fine. I suggest looking at the sample prefab object - you can tear it down and use whatever part you like. The one you NEED to have is the tk2dUIItem, everything else is optional. In fact it might work better in your case, as you don't need to tweak the "button" to behave like a clickable object. tk2dUIItem IS a clickable object, the button behaviour goes on top of it.
Title: Re: tk2dButton clicks doesn't work on Unity4.2 beta
Post by: kremedved on July 23, 2013, 11:31:04 am
After the fix, the method name of tk2button occurs when I press the button down, but I need it to occur when I press the button up