- Home /
Simple state switching to mouse over & pressed requires 2 animation clips with some parts duplicated?
I have a simple demo like this. There is a gameObject (like a Quad) in the scene. It should have 2 states:
1. MouseOver
2. MouseOver and pressed at the same time.
The state MouseOver should highlight its border (square border). If the user presses the mouse while it's in the MouseOver state, its background should change (of course the square border should be still present). I wonder if there is some way to add the second effect (showing the background) to the current state (MouseOver) to build the MouseOver & Pressed state? Currently I have to prepare 2 different animation clips, the first for MouseOver and the second for MouseOver & pressed. You can see that the second animation clip "contains" the first meaning I have to duplicate some steps to add the animation curve (like in the MouseOver animation clip) beside adding the extra curve for showing the background.
I want some kind of reusability and inheritance of animation clip/effects. It would be much more flexible and easier to maintain. (like the way you can do with WPF animations). In other words, I want to avoid the duplication between the 2 animation clips. At least we should have some easy way to copy some curve from this clip to another clip without having to rebuild the curves manually.
Thanks for your help.
More clarification:
Think about the process of creating the 2 animation clips (for the 2 states):
For mouseover state:
Add the only simple animation curve to show some child gameObject. This child renders the border. (So hovering over the main gameObject will show its border).
For mouseover & pressed state:
Duplicate the step of creating the exact animation curve done above.
Add one more simple animation curve to show the background. (So hovering and pressing the main gameObject will show both its border and its background).
In this case the example is just simple, so the duplication can be done easily. However in many complex situations, the duplication is large while the difference between states is just tiny but you still need to create separate animation clips with all the duplicated steps being done manually. I would like to avoid or eliminate the duplicated steps as much as possible. If that's not possible, there should be at least some easy way to copy the animation curves so that the duplication can be done easily and exactly.
I hope now you understand my problem.
@tanoshimi did you mean the question is unclear? $$anonymous$$aybe I did not express it well but I think it's still understandable. Just focus on the duplicated steps you have to do to create 2 animation clips. I would like to avoid that kind of duplication or at least there should be some way to copy the animation curves easily.
Are you just looking for a button functionality? Or do you plan to implement it on mesh rendered gameObjects?
@tanoshimi if you meant the question was unclear, please see the clarification I updated, thanks!
@lordlycastle actually this can be applied on both 2D and 3D gameObjects, although at first I was more interested in 2D objects of course including UI objects.
Answer by lordlycastle · Mar 01, 2015 at 06:42 PM
What you are looking for is Transitions, especially for UI's. Have a look at this video, it explains them very well, how to create them, so you can use them for different UI objects.
Creating effects for for 3D objects, is slightly more tedious if they have different meshes. If you just need to give the user feedback as to what their mouse is on, then you can simple implement a colour change of the renderer's material, in OnMouseEnter() method. That method is called whenever the mouse enters a collider or GUI. If colour change is not possible, you can change transform, but remember to change the rigid body's position if it's physics object.Or if you want something fancy, enable/disable a particle emitter component.
The second state you are looking for is OnMouseDown(), which is called when mouse is on the collider, and pressed.
maybe you misunderstand my question a little. UI transition is convenient but UI is not the only one kind of object I care about. Generally it should be any gameObject. Secondly I want to use Animation Clip to make the effect, handling On$$anonymous$$ouseEnter or something similar should end up triggering some animation clip. Please review my clarification which should describe the problem clearly enough. You can see that you cannot avoid duplicated steps, of course unless you know how to do.
Your answer
![](https://koobas.hobune.stream/wayback/20220613184553im_/https://answers.unity.com/themes/thub/images/avi.jpg)