@@ -163,11 +163,7 @@ internal void Update(float deltaTime)
163163 {
164164 if ( this . IsPlaying )
165165 {
166- if ( this . elapsed >= this . duration )
167- {
168- Complete ( ) ;
169- }
170- else if ( ! this . IsDelayed )
166+ if ( ! this . IsDelayed )
171167 {
172168 this . elapsed += deltaTime ;
173169
@@ -177,10 +173,21 @@ internal void Update(float deltaTime)
177173 if ( this . onUpdate != null ) {
178174 this . onUpdate . Invoke ( ) ;
179175 }
176+
177+ if ( CanComplete ( ) ) {
178+ Complete ( ) ;
179+ }
180180 }
181181 else
182182 {
183183 this . delayElapsed += deltaTime ;
184+
185+ // Start the tween once the delay is complete and only if
186+ // the elapsed time is zero which indicates it has never
187+ // been updated yet
188+ if ( this . elapsed == 0 && this . delayElapsed >= this . delay ) {
189+ Start ( ) ;
190+ }
184191 }
185192 }
186193 else if ( this . state == TweenState . Ready && this . autoStart )
@@ -213,15 +220,26 @@ public void Play()
213220 this . elapsed = 0.0f ;
214221 this . delayElapsed = 0.0f ;
215222
216- OnStart ( ) ;
217- Animate ( ) ;
218-
219- if ( this . onStart != null ) {
220- this . onStart . Invoke ( ) ;
223+ // Start right away if there is no delay
224+ if ( ! this . IsDelayed ) {
225+ Start ( ) ;
221226 }
222227 }
223228 }
224229
230+ /// <summary>
231+ /// Starts the tween for the first time.
232+ /// </summary>
233+ private void Start ( )
234+ {
235+ OnStart ( ) ;
236+ Animate ( ) ;
237+
238+ if ( this . onStart != null ) {
239+ this . onStart . Invoke ( ) ;
240+ }
241+ }
242+
225243 /// <summary>
226244 /// Stops the tween if currently being played.
227245 /// </summary>
@@ -327,6 +345,7 @@ internal void Reset()
327345 OnReset ( ) ;
328346 }
329347
348+ protected virtual bool CanComplete ( ) => this . elapsed >= this . duration ;
330349 protected virtual void OnUpdate ( ) { }
331350 protected virtual void OnStart ( ) { }
332351 protected virtual void OnStop ( ) { }
0 commit comments