# do something on a button down?

**URL:** <https://discussions.unity.com/t/do-something-on-a-button-down/396139>\
**Category:** UI\
**Tags:** IMGUI\
**Created:** [August 8, 2009, 9:55am UTC](https://discussions.unity.com/t/do-something-on-a-button-down/396139 "2009-08-08T09:55:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mctricks](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@mctricks](https://discussions.unity.com/u/mctricks)\
**Post date:** [August 8, 2009, 9:55am UTC](https://discussions.unity.com/t/do-something-on-a-button-down/396139/1 "2009-08-08T09:55:46Z")

</div>

I’ve noticed that with GUI.button, all the events happen on button up. Can I do something on button down too? (do something on button down, AND up, all on the same button)

to give you an exact idea of what I’m trying to do… I’m making the menu’s for my game, and the texture needs to change on button down, and do the action the button is supposed to do on button up.

Thanks in advanced 😄

---

<div class="post-metadata">

**Author:** ![Quietus2](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/quietus2/32/444325_2.png) [@Quietus2](https://discussions.unity.com/u/Quietus2)\
**Post date:** [August 8, 2009, 10:05am UTC](https://discussions.unity.com/t/do-something-on-a-button-down/396139/2 "2009-08-08T10:05:20Z")

</div>

I don’t believe that’s possible by using the stock unity GUI. However you can probably effect just such a thing with a combination of a few other Unity api’s.

Is my mouse over a particular collider pretending to be a button?

> **[Unity - Scripting API: MonoBehaviour.OnMouseOver()](https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseOver.html)**

Is the mouse button pressed down? If case one and two are set high, change my texture.

> **[Unity - Scripting API: MonoBehaviour.OnMouseDown()](https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html)**

And the last piece of the puzzle. If case 1 and 3 are high, change texture again, execute function etc.

> **[Unity - Scripting API: MonoBehaviour.OnMouseUp()](https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseUp.html)**

---

<div class="post-metadata">

**Author:** ![anon\_85768832](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@anon\_85768832](https://discussions.unity.com/u/anon_85768832)\
**Post date:** [August 10, 2009, 8:47pm UTC](https://discussions.unity.com/t/do-something-on-a-button-down/396139/3 "2009-08-10T20:47:29Z")

</div>

If all you want to do is to change the texture of a button on mouse down then use a GUIStyle and set the active state’s texture to whatever you’d like.

---

<div class="post-metadata">

**Author:** ![silencer](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@silencer](https://discussions.unity.com/u/silencer)\
**Post date:** [August 11, 2009, 9:26pm UTC](https://discussions.unity.com/t/do-something-on-a-button-down/396139/4 "2009-08-11T21:26:05Z")

</div>

How do you make a texture completely replace/become a button?

---

<div class="post-metadata">

**Author:** ![anon\_85768832](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@anon\_85768832](https://discussions.unity.com/u/anon_85768832)\
**Post date:** [August 11, 2009, 11:06pm UTC](https://discussions.unity.com/t/do-something-on-a-button-down/396139/5 "2009-08-11T23:06:59Z")

</div>

First off, welcome to the forums silencer! 😄

> [@""](#):
>
> How do you make a texture completely replace/become a button?

You do that by setting the [GUISkin](http://unity3d.com/support/documentation/Components/class-GUISkin.html) you’re using (setting the button’s active state background texture), but that applies to all buttons. If instead you want something to affect only that button in particular then you can create and assign a specific custom [GUIStyle](http://unity3d.com/support/documentation/Components/class-GUIStyle.html).

For more information, check out the [GUI Scripting Guide](http://unity3d.com/support/documentation/Components/GUI%20Scripting%20Guide.html).

---

<div class="post-metadata">

**Author:** ![silencer](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@silencer](https://discussions.unity.com/u/silencer)\
**Post date:** [August 11, 2009, 11:19pm UTC](https://discussions.unity.com/t/do-something-on-a-button-down/396139/6 "2009-08-11T23:19:09Z")

</div>

I see. Easy enough I suppose.

---

<div class="post-metadata">

**Author:** ![anon\_85768832](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@anon\_85768832](https://discussions.unity.com/u/anon_85768832)\
**Post date:** [August 11, 2009, 11:23pm UTC](https://discussions.unity.com/t/do-something-on-a-button-down/396139/7 "2009-08-11T23:23:42Z")

</div>

> [@""](#):
>
> I see. Easy enough I suppose.

It is quite easy. You can even add a GUISkin to your scene, define a custom style (including textures) in the Inspector, then easily apply that style by name at run-time (think of GUIStyles as being like a CSS style).

Give it a go and post up and follow-up questions you have. Oh, and have fun! 🙂
