- Home /
How to animate property-changes properly
I'm developing a game using Unity.
Here's an example of how I animate property-changes (like alpha-value of the color/position/counting up numbers).
Is there a better way to handle such changes over time?
EDIT: I'd like to be able to trigger an event or execute code once the animation is finished
public class myObject : MonoBehaviour{
//enum indicating the state of the object
public enum State {
Ready,
Disappearing
}
private State objState = State.Ready;
Update (){
if (objState == State.Disappearing){
Color oldColor = this.gameObject.GetComponent<Text>().color;
oldColor.a -= Time.deltaTime; //disappearing takes one second
if (oldColor.a <= 0.0f){
oldColor.a = 0;
objState = State.Ready;
}
this.gameObject.GetComponent<Text>().color = oldColor;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Easier way of creating transitions in the animator? 1 Answer
if animator state=x 1 Answer
Animation mecanim state 1 Answer
How do I make the transition between two states in the "Animator" happen instantly? 3 Answers
How to get fileID information so i can just edit Mecanim Animator through script? 2 Answers