Author Topic: Simulate Mouse click Button on Key Input  (Read 3192 times)

Danim3D

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
    • http://www.Danim3D.com
Simulate Mouse click Button on Key Input
« on: August 13, 2015, 06:06:52 PM »
I am trying to Simulate a Mouse click on an NGUI Button with a Keyboard Input.

I have try the UIKeyBinding script and this line bellow but the UIPlayAnimation and fonction doesn't execute, only the sound play.
I would like to know what I'm doing wrong. Thank!

if(Input.GetKeyUp(KeyCode.Escape))
      buttonGameObject.SendMessage("OnClick", SendMessageOptions.DontRequireReceiver);
« Last Edit: August 13, 2015, 07:25:51 PM by Danim3D »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Simulate Mouse click Button on Key Input
« Reply #1 on: August 14, 2015, 09:31:11 AM »
Open up UIPlayAnimation.cs, find the OnClick function and change it to be:
  1.         void OnClick ()
  2.         {
  3.                 if (UICamera.currentTouchID == -2 || UICamera.currentTouchID == -3) return; // <-- this changes
  4.                 if (enabled && trigger == Trigger.OnClick) Play(true, false);
  5.         }

Danim3D

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
    • http://www.Danim3D.com
Re: Simulate Mouse click Button on Key Input
« Reply #2 on: August 14, 2015, 02:48:59 PM »
Thank, it work  :D