|
|
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class CubeWithCrystals : MonoBehaviour
- {
- bool characterInWater = false;
- public GameObject crystals;
-
- IEnumerator GrowShrinkCoroutine(Vector3 endPosition)
- {
- float elapsedTime = 0;
- Vector3 startPosition = crystals.transform.position;
- float time = 0.8f;
- while (elapsedTime < time)
- {
- transform.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
- yield return new WaitForEndOfFrame();
- elapsedTime += Time.deltaTime;
- }
- crystals.transform.position = endPosition;
- }
-
- public void Animate()
- {
- StartCoroutine(GrowShrinkCoroutine(new Vector3(0, 1, 0)));
- }
- public void returnToPosition()
- {
- StartCoroutine(GrowShrinkCoroutine(new Vector3(0, 0, 0)));
- }
- }
|