Author Topic: OnPress doesn't seem to be working properly - or am I using it wrong?  (Read 2571 times)

KayEffEff

  • Guest
I made a game object, gave it a collider, and put the following script on it:

  1. public bool Pressed = false;
  2.  
  3. void OnPress ()
  4. {
  5.      Pressed = true;
  6. }

When I hover my mouse cursor over the collider and click down, Pressed is not set to true. However, if I release the mouse button and then click down again, it will turn true this time.

I want "Pressed" to turn true the first time I click down, not the second time. What am I doing wrong?
« Last Edit: February 17, 2013, 05:43:34 PM by KayEffEff »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnPress doesn't seem to be working properly - or am I using it wrong?
« Reply #1 on: February 17, 2013, 06:55:34 PM »
  1. void OnPress (bool isPressed)

KayEffEff

  • Guest
Re: OnPress doesn't seem to be working properly - or am I using it wrong?
« Reply #2 on: February 17, 2013, 07:56:55 PM »
I tried experimenting with isPressed, but it didn't seem to give me the desired results. Here's what I tried:

  1. public bool Pressed = false;
  2.  
  3. void OnPress (bool isPressed)
  4. {
  5.      if (isPressed == true)
  6.      {
  7.           Pressed = true;
  8.      }
  9. }

This code results in the button only reacting when the mouse button is released - the opposite of what I'd expect it to do. And saying "if(isPressed == false)" resulted in no reaction whatsoever.

I've been using NGUI for months, and every other aspect of NGUI works perfectly for me, but I always run into this problem when I try to use OnPress. I must be doing something really stupid without realizing it. Are there any common "gotcha" mistakes to look out for when using OnPress?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnPress doesn't seem to be working properly - or am I using it wrong?
« Reply #3 on: February 17, 2013, 08:51:20 PM »
Eh?
  1. public bool Pressed = false;
  2.  
  3. void OnPress (bool isPressed) { Pressed = isPressed; }

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: OnPress doesn't seem to be working properly - or am I using it wrong?
« Reply #4 on: February 18, 2013, 05:33:42 AM »
OnPress gets a true param when pressed and a false when released.

Everything else is on your end. :)