Spirits_Float.cs 957 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Spirits_Float : MonoBehaviour
  5. {
  6. private bool isRise = true;
  7. public float height; //Éýµ½Äĸö¸ß¶ÈºóÍ£Ö¹
  8. private float curHeight;
  9. private float speed = 1;
  10. private Vector3 origPos;
  11. private void Start()
  12. {
  13. origPos = transform.position;
  14. curHeight = origPos.y;
  15. }
  16. private void MoveToHeight()
  17. {
  18. curHeight = Mathf.SmoothDamp(curHeight, height, ref speed, 0.02f);
  19. transform.position = new Vector3(origPos.x, curHeight, origPos.z);
  20. }
  21. private void Update()
  22. {
  23. if (isRise)
  24. {
  25. MoveToHeight();
  26. if (curHeight - height <= 0.02f && curHeight - height >= -0.02f)
  27. {
  28. isRise = false;
  29. curHeight = height;
  30. transform.position = new Vector3(origPos.x, height, origPos.z);
  31. }
  32. }
  33. }
  34. }