05-17 06:36
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

How to Play Animation Sequence in Unity 본문

CG & Video Games/Unity 3D

How to Play Animation Sequence in Unity

cinema4dr12 2013. 5. 26. 20:20
  1. #pragma strict
  2.  
  3. /* Animation Switching
  4. - Put this script on the object you want to switch animation clips
  5. - Fill out the clip names (as named in project) on Animation Names in the order you want to play them
  6. */
  7.  
  8. var animationNames : String[]; //Fill out the names in the Inspector
  9.  
  10. private var currentAnimation : int = 0; //Keep track of our current animation
  11. private var animationComponent : Animation; //Cache the Animation Component
  12.  
  13. function Start () {
  14. animationComponent = GetComponent(Animation);
  15. }
  16.  
  17. function Update () {
  18. if (Input.GetButtonDown("Fire1")) {
  19. playAnimation();
  20. }
  21. }
  22.  
  23. function playAnimation () {
  24. if(!animation.isPlaying) {
  25. animation.Play(animationNames[currentAnimation]);
  26. currentAnimation++;
  27. if(currentAnimation>=animationComponent.GetClipCount()) {
  28. currentAnimation=0;
  29. }
  30. }
  31. }


Comments