Game Development Reference
In-Depth Information
33 //--------------------------------------------------------------
34 void Start()
35 {
36 //Should we auto-play at start up?
37 if(AutoPlay){StartCoroutine(PlaySpriteAnimation(AnimationID));}
38 }
39 //--------------------------------------------------------------
40 //Function to run animation
41 public IEnumerator PlaySpriteAnimation(int AnimID = 0)
42 {
43 //Check if this animation should be started. Could be called via SendMessage or
BroadcastMessage
44 if(AnimID!= AnimationID) yield break;
45
46 //Should hide all sprite renderers?
47 if(HideSpritesOnStart)
48 {
49 foreach(SpriteRenderer SR in Sprites)
50 SR.enabled = false;
51 }
52
53 //Set is playing
54 IsPlaying = true;
55
56 //Calculate delay time
57 float DelayTime = 1.0f/FPS;
58
59 //Run animation at least once
60 do
61 {
62 foreach(SpriteRenderer SR in Sprites)
63 {
64 SR.enabled = !SR.enabled;
65 yield return new WaitForSeconds(DelayTime);
66 SR.enabled = !SR.enabled;
67 }
68 }
69 while(PlaybackType == ANIMATOR_PLAYBACK_TYPE.PLAYLOOP);
70
71 //Stop animation
72 StopSpriteAnimation(AnimationID);
73 }
74 //--------------------------------------------------------------
75 //Function to stop animation
76 public void StopSpriteAnimation(int AnimID = 0)
77 {
78 //Check if this animation can and should be stopped
79 if((AnimID!= AnimationID) || (!IsPlaying)) return;
80
81 //Stop all coroutines (animation will no longer play)
82 StopAllCoroutines();
83
Search WWH ::




Custom Search