You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.2 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. public class AnimationScript : MonoBehaviour {
  4. public bool isAnimated = false;
  5. public bool isRotating = false;
  6. public bool isFloating = false;
  7. public bool isScaling = false;
  8. public Vector3 rotationAngle;
  9. public float rotationSpeed;
  10. public float floatSpeed;
  11. private bool goingUp = true;
  12. public float floatRate;
  13. private float floatTimer;
  14. public Vector3 startScale;
  15. public Vector3 endScale;
  16. private bool scalingUp = true;
  17. public float scaleSpeed;
  18. public float scaleRate;
  19. private float scaleTimer;
  20. // Use this for initialization
  21. void Start () {
  22. }
  23. // Update is called once per frame
  24. void Update () {
  25. if(isAnimated)
  26. {
  27. if(isRotating)
  28. {
  29. transform.Rotate(rotationAngle * rotationSpeed * Time.deltaTime);
  30. }
  31. if(isFloating)
  32. {
  33. floatTimer += Time.deltaTime;
  34. Vector3 moveDir = new Vector3(0.0f, 0.0f, floatSpeed);
  35. transform.Translate(moveDir);
  36. if (goingUp && floatTimer >= floatRate)
  37. {
  38. goingUp = false;
  39. floatTimer = 0;
  40. floatSpeed = -floatSpeed;
  41. }
  42. else if(!goingUp && floatTimer >= floatRate)
  43. {
  44. goingUp = true;
  45. floatTimer = 0;
  46. floatSpeed = +floatSpeed;
  47. }
  48. }
  49. if(isScaling)
  50. {
  51. scaleTimer += Time.deltaTime;
  52. if (scalingUp)
  53. {
  54. transform.localScale = Vector3.Lerp(transform.localScale, endScale, scaleSpeed * Time.deltaTime);
  55. }
  56. else if (!scalingUp)
  57. {
  58. transform.localScale = Vector3.Lerp(transform.localScale, startScale, scaleSpeed * Time.deltaTime);
  59. }
  60. if(scaleTimer >= scaleRate)
  61. {
  62. if (scalingUp) { scalingUp = false; }
  63. else if (!scalingUp) { scalingUp = true; }
  64. scaleTimer = 0;
  65. }
  66. }
  67. }
  68. }
  69. }