Following.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Following : MonoBehaviour {
  5. public Transform planet;
  6. public Transform followArrow;
  7. public Transform dude1;
  8. public Transform dude2;
  9. public Transform dude3;
  10. public Transform dude4;
  11. public Transform dude5;
  12. public Transform dude1Title;
  13. public Transform dude2Title;
  14. public Transform dude3Title;
  15. public Transform dude4Title;
  16. public Transform dude5Title;
  17. private Color dude1ColorVelocity;
  18. private Vector3 velocityPos;
  19. private void Start()
  20. {
  21. followArrow.gameObject.LeanDelayedCall(3f, moveArrow).setOnStart(moveArrow).setRepeat(-1);
  22. // Follow Local Y Position of Arrow
  23. LeanTween.followDamp(dude1, followArrow, LeanProp.localY, 1.1f);
  24. LeanTween.followSpring(dude2, followArrow, LeanProp.localY, 1.1f);
  25. LeanTween.followBounceOut(dude3, followArrow, LeanProp.localY, 1.1f);
  26. LeanTween.followSpring(dude4, followArrow, LeanProp.localY, 1.1f, -1f, 1.5f, 0.8f);
  27. LeanTween.followLinear(dude5, followArrow, LeanProp.localY, 50f);
  28. // Follow Arrow color
  29. LeanTween.followDamp(dude1, followArrow, LeanProp.color, 1.1f);
  30. LeanTween.followSpring(dude2, followArrow, LeanProp.color, 1.1f);
  31. LeanTween.followBounceOut(dude3, followArrow, LeanProp.color, 1.1f);
  32. LeanTween.followSpring(dude4, followArrow, LeanProp.color, 1.1f, -1f, 1.5f, 0.8f);
  33. LeanTween.followLinear(dude5, followArrow, LeanProp.color, 0.5f);
  34. // Follow Arrow scale
  35. LeanTween.followDamp(dude1, followArrow, LeanProp.scale, 1.1f);
  36. LeanTween.followSpring(dude2, followArrow, LeanProp.scale, 1.1f);
  37. LeanTween.followBounceOut(dude3, followArrow, LeanProp.scale, 1.1f);
  38. LeanTween.followSpring(dude4, followArrow, LeanProp.scale, 1.1f, -1f, 1.5f, 0.8f);
  39. LeanTween.followLinear(dude5, followArrow, LeanProp.scale, 5f);
  40. // Titles
  41. var titleOffset = new Vector3(0.0f, -20f, -18f);
  42. LeanTween.followDamp(dude1Title, dude1, LeanProp.localPosition, 0.6f).setOffset(titleOffset);
  43. LeanTween.followSpring(dude2Title, dude2, LeanProp.localPosition, 0.6f).setOffset(titleOffset);
  44. LeanTween.followBounceOut(dude3Title, dude3, LeanProp.localPosition, 0.6f).setOffset(titleOffset);
  45. LeanTween.followSpring(dude4Title, dude4, LeanProp.localPosition, 0.6f, -1f, 1.5f, 0.8f).setOffset(titleOffset);
  46. LeanTween.followLinear(dude5Title, dude5, LeanProp.localPosition, 30f).setOffset(titleOffset);
  47. // Rotate Planet
  48. var localPos = Camera.main.transform.InverseTransformPoint(planet.transform.position);
  49. LeanTween.rotateAround(Camera.main.gameObject, Vector3.left, 360f, 300f).setPoint(localPos).setRepeat(-1);
  50. }
  51. private float fromY;
  52. private float velocityY;
  53. private Vector3 fromVec3;
  54. private Vector3 velocityVec3;
  55. private Color fromColor;
  56. private Color velocityColor;
  57. private void Update()
  58. {
  59. // Use the smooth methods to follow variables in which ever manner you wish!
  60. fromY = LeanSmooth.spring(fromY, followArrow.localPosition.y, ref velocityY, 1.1f);
  61. fromVec3 = LeanSmooth.spring(fromVec3, dude5Title.localPosition, ref velocityVec3, 1.1f);
  62. fromColor = LeanSmooth.spring(fromColor, dude1.GetComponent<Renderer>().material.color, ref velocityColor, 1.1f);
  63. Debug.Log("Smoothed y:" + fromY + " vec3:" + fromVec3 + " color:" + fromColor);
  64. }
  65. private void moveArrow()
  66. {
  67. LeanTween.moveLocalY(followArrow.gameObject, Random.Range(-100f, 100f), 0f);
  68. var randomCol = new Color(Random.value, Random.value, Random.value);
  69. LeanTween.color(followArrow.gameObject, randomCol, 0f);
  70. var randomVal = Random.Range(5f, 10f);
  71. followArrow.localScale = Vector3.one * randomVal;
  72. }
  73. }