Author Topic: Label being a Button  (Read 1687 times)

BehindTheStone

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 135
    • View Profile
Label being a Button
« on: January 11, 2014, 09:30:10 AM »
Hey there!

So this is what I want to achieve:

I have a Bookmenu for the Quests. And everytime a quest is accepted a Label (the name of the quest) will be added to a Grid. This grid has also a custom script attached and has an ArrayList which adds every new Quest/Label to this list.

So, when I open the Questmenu (clicking on a normal UIButton) ALL these ListItems (the labels) shall:

- set active to true
- play a Tween (fade in)
- stay in their state (meaning, the alpha value should stay at 1.0f)

That's not the "hard" part. So now we're in the Questmenu and see the names (the labels) of the accepted Quests. NOW when we hit ONE of these labels, ALL of them should:

- play a Tween (fade out to 0.0f)
- set active to false

and then the particular QuestPage should be shown.

In order to get this working I attached a BoxCollider to my labels. What I can't manage to find is the way to access the information that any of the label in the list has been clicked.

I already tried something like this after some research: http://www.tasharen.com/forum/index.php?topic=6987.msg32984#msg32984

Quote
void Update ()
   {

      foreach(GameObject q in questList)
      {
         UIEventListener.Get(q).onClick += Clicked;

      }
   }


   void Clicked()
   {
      Debug.Log ("Any was clicked");
   }

But it just gives me errors.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Label being a Button
« Reply #1 on: January 11, 2014, 05:54:51 PM »
UIListener's OnClick notification passes the "GameObject" parameter. You're missing that parameter in your function declaration.

Note that if you have a UIButton script on that object, you can simply use its OnClick notification (which doesn't require a parameter), and you'd use UIButton.current to determine who triggered the delegate.

BehindTheStone

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 135
    • View Profile
Re: Label being a Button
« Reply #2 on: January 11, 2014, 06:26:29 PM »
Ah, you mean simply:

  1. void Clicked(GameObject g)
  2.         {
  3.                 // Debug.Log("Any was clicked");
  4.         }

That got rid of the errors, indeed, but it doesn't seem to work. When I click a Label which are also in the list, nothing Debugs.

(Edit: Don't think it doesn't Debug because of the CommentPart, the actual code does not have "//"  ;)  )

I wanted to use the UIButton-Script in the first place! But the Colors are bugging me :D
The idea was: when I click a Label it should fade out, but when I do so and hover around the area it immediately sets for some frames  its alpha-value back to 1 in order to represent the Hover-Color and then fades-out again.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Label being a Button
« Reply #3 on: January 11, 2014, 06:31:05 PM »
Set the 'debug' flag on your UI camera to see what's under the mouse.