Hello Guest

Author Topic: tk2dbutton and raycast issue  (Read 6343 times)

jpb1614

  • Newbie
  • *
  • Posts: 4
    • View Profile
tk2dbutton and raycast issue
« on: June 14, 2012, 02:53:48 am »
Hello,

I seem to be having trouble with tkbuttons. I have been using them and have got them to work correctly, until I tried to use them in my game screen where I use raycast. I have searched for an answer but have come up empty handed. The only thing I was able to find is that it is a known issue currently. I also read that there is a workaround. I was hoping someone could direct me to the workaround if possible. Any other information is greatly appreciated. Thanks

-Jarryd

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dbutton and raycast issue
« Reply #1 on: June 14, 2012, 05:05:58 pm »
Hi,
I need a bit more info on this - what doesn't work in game? The buttons should definitely work in game. What objects are you attaching the tk2dButton script to?

unikron

jpb1614

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: tk2dbutton and raycast issue
« Reply #2 on: June 14, 2012, 05:29:53 pm »
Hi,
Thanks for the response. The buttons are working perfectly on my main menu where I have created a tk2dtextmesh, then added the tk2dbutton component to them. I've tested these and they work great.

In my actual game screen, I have a sprite on the left side, which represents the player, then I have hordes of monsters coming from the right side towards the player. When the player clicks, an icebolt is shot at the mouse's current location. I'm using raycast for this. Anyway, I was wanting to have a few buttons on this screen in order to swap between spells the player can use, fire, ice, whatever. I used the same method I did with the main screen button. I created a tk2dtextmesh, and attached a tk2dbutton component to that textmesh. I did exactly as I had for my previous button on the main menu, yet the buttons on this screen can't be clicked. I searched for quite a while and the only information I came up with is that there was a bug with the buttons while using raycast. Maybe I've been looking in the wrong place, but I've recreated this scene multiple times thinking I was just making a minor error, but all ended with unclickable buttons. I even went as far as adding a script that would be called when they're clicked with a debug log saying "clicked". No luck as of yet. I hope this is enough information, if not please let me know what else would be helpful. Thanks again.

-Jarryd

P.S The reason I'm stressing raycast is that was the only information I could find on this problem. However, when I disabled the script that used raycast, buttons still couldn't be clicked. I use raycast in the bullet that is shot when clicked, so I just disabled the bullet prefab being spawned when clicked.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dbutton and raycast issue
« Reply #3 on: June 14, 2012, 06:12:47 pm »
Oh. The "bug" you speak of is probably this - if the bounding box of the button is too close to the camera, in such a way that the origin of the camera would be inside it, then the raycast wouldn't work (and as a result, the button won't work either).

Can you check for this ?

jpb1614

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: tk2dbutton and raycast issue
« Reply #4 on: June 14, 2012, 06:26:30 pm »
Thanks again for the help. Sorry to have wasted your time, it must have been a bug with my machine. I restarted to install updates and was about to try what you asked, when I tried one more time, they now work. I haven't changed anything, yet they work now! Thanks for your time, I really appreciate it.

-Jarryd

astral

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: tk2dbutton and raycast issue
« Reply #5 on: October 12, 2012, 01:21:00 pm »
Oh. The "bug" you speak of is probably this - if the bounding box of the button is too close to the camera, in such a way that the origin of the camera would be inside it, then the raycast wouldn't work (and as a result, the button won't work either).

Thanks!