|
|
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class CubeWithCrystals : MonoBehaviour
- {
- public GameObject crystals;
- public bool triggeranimate;
- public bool triggeranimate1;
-
- private void Update()
- {
-
- }
-
- IEnumerator GrowCoroutine()
- {
- float elapsedTime = 0;
- Vector3 startPosition = crystals.transform.position;
- Vector3 endPosition = new Vector3(crystals.transform.position.x, crystals.transform.position.y + 1.0f, crystals.transform.position.z);
- 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;
- }
- IEnumerator ShrinkCoroutine()
- {
- float elapsedTime = 0;
- Vector3 startPosition = crystals.transform.position;
- Vector3 endPosition = new Vector3(crystals.transform.position.x, crystals.transform.position.y - 1.0f, crystals.transform.position.z);
- 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(GrowCoroutine());
- }
- public void returnToPosition()
- {
- StartCoroutine(ShrinkCoroutine());
- }
- }
|