Author Topic: OnHover function: saving "isOver" as a local boolean variable  (Read 3585 times)

Bunni

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
OnHover function: saving "isOver" as a local boolean variable
« on: August 21, 2014, 03:33:35 PM »
First, I just want to say this is a really neat package.  I am definitely considering upgrading from the free version after I learn the ins and outs of the code more thoroughly.  Right now I am trying to implement two "left" and "right" buttons that scroll a panel when they are moused over.  I seem to have the scrolling part right, but I read that since NGUI does not continuously fire events (from this thread), I will have to assign isOver to a local variable which I named "pressed". 
  1. public class MouseOverScroll : UIButton {
  2.  
  3.         public enum Direction{Left, Right};
  4.         public Direction dir = Direction.Left;
  5.         public GameObject dragpanel;
  6.         UIDraggablePanel dps;
  7.         public bool pressed = false;
  8.  
  9.         void Start () {
  10.                 dps = dragpanel.GetComponent<UIDraggablePanel> ();
  11.         }
  12.         void Update() {
  13.                 if(pressed) {
  14.                         if (dir == Direction.Left) {
  15.                                 dps.SendMessage("Scroll", 0.5f);
  16.                         }
  17.                         else if (dir == Direction.Right) {
  18.                                 dps.SendMessage("Scroll", -0.5f);
  19.                         }
  20.                 }
  21.         }
  22.         public override void OnHover (bool isOver)
  23.         {
  24.                 base.OnHover (isOver);
  25.                 pressed = isOver;
  26.         }
  27. }
  28.  

However this started giving me the error: "The same field name is serialized multiple times in the class or its parent class.  This is not supported: Base(Monobehaviour) pressed".  I guess it doesn't like what I am doing in void OnHover(), but why?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnHover function: saving "isOver" as a local boolean variable
« Reply #1 on: August 22, 2014, 04:40:28 AM »
That message shows up when you have a derived class have a field that has the same name as that of its base class. Just rename your "pressed" to "mPressed" or something similar.

P.S. You may want to upgrade sooner rather than later if you're actually doing any UI work. NGUI 3 is quite different from 2, and while NGUI 2 UI layouts will auto-upgrade (mostly) fine, the code won't.