GeneralSequencer.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class GeneralSequencer : MonoBehaviour {
  5. public GameObject avatar1;
  6. public GameObject star;
  7. public GameObject dustCloudPrefab;
  8. public float speedScale = 1f;
  9. public void Start(){
  10. // Jump up
  11. var seq = LeanTween.sequence();
  12. seq.append( LeanTween.moveY( avatar1, avatar1.transform.localPosition.y + 6f, 1f).setEaseOutQuad() );
  13. // Power up star, use insert when you want to branch off from the regular sequence (this does not push back the delay of other subsequent tweens)
  14. seq.insert( LeanTween.alpha(star, 0f, 1f) );
  15. seq.insert( LeanTween.scale( star, Vector3.one * 3f, 1f) );
  16. // Rotate 360
  17. seq.append( LeanTween.rotateAround( avatar1, Vector3.forward, 360f, 0.6f ).setEaseInBack() );
  18. // Return to ground
  19. seq.append( LeanTween.moveY( avatar1, avatar1.transform.localPosition.y, 1f).setEaseInQuad() );
  20. // Kick off spiraling clouds - Example of appending a callback method
  21. seq.append(() => {
  22. for(int i = 0; i < 50f; i++){
  23. GameObject cloud = Instantiate(dustCloudPrefab) as GameObject;
  24. cloud.transform.parent = avatar1.transform;
  25. cloud.transform.localPosition = new Vector3(Random.Range(-2f,2f),0f,0f);
  26. cloud.transform.eulerAngles = new Vector3(0f,0f,Random.Range(0,360f));
  27. var range = new Vector3(cloud.transform.localPosition.x, Random.Range(2f,4f), Random.Range(-10f,10f));
  28. // Tweens not in a sequence, because we want them all to animate at the same time
  29. LeanTween.moveLocal(cloud, range, 3f*speedScale).setEaseOutCirc();
  30. LeanTween.rotateAround(cloud, Vector3.forward, 360f*2, 3f*speedScale).setEaseOutCirc();
  31. LeanTween.alpha(cloud, 0f, 3f*speedScale).setEaseOutCirc().setDestroyOnComplete(true);
  32. }
  33. });
  34. // You can speed up or slow down the sequence of events
  35. seq.setScale(speedScale);
  36. // seq.reverse(); // not working yet
  37. // Testing canceling sequence after a bit of time
  38. //LeanTween.delayedCall(3f, () =>
  39. //{
  40. // LeanTween.cancel(seq.id);
  41. //});
  42. }
  43. }