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.
 
 
 
 
 
 

53 lines
1.6 KiB

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());
}
}