| 1234567891011121314151617181920212223242526272829303132333435363738 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Spirits_Float : MonoBehaviour
- {
- private bool isRise = true;
- public float height; //Éýµ½Äĸö¸ß¶ÈºóÍ£Ö¹
- private float curHeight;
- private float speed = 1;
- private Vector3 origPos;
- private void Start()
- {
- origPos = transform.position;
- curHeight = origPos.y;
- }
- private void MoveToHeight()
- {
- curHeight = Mathf.SmoothDamp(curHeight, height, ref speed, 0.02f);
- transform.position = new Vector3(origPos.x, curHeight, origPos.z);
- }
- private void Update()
- {
- if (isRise)
- {
- MoveToHeight();
- if (curHeight - height <= 0.02f && curHeight - height >= -0.02f)
- {
- isRise = false;
- curHeight = height;
- transform.position = new Vector3(origPos.x, height, origPos.z);
- }
- }
- }
- }
|