using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DrawLinesAnimated : MonoBehaviour
{
public Transform[] objectsToScale;
private void Start()
{
for (int i = 0; i < objectsToScale.Length; i++)
{
StartCoroutine(scaleOverTime(objectsToScale[i], new Vector3(2, objectsToScale[i].transform.localScale.y, objectsToScale[i].transform.localScale.z), 2));
}
}
bool isScaling = false;
IEnumerator scaleOverTime(Transform objectToScale, Vector3 toScale, float duration)
{
//Make sure there is only one instance of this function running
if (isScaling)
{
yield break; ///exit if this is still running
}
isScaling = true;
float counter = 0;
//Get the current scale of the object to be moved
Vector3 startScaleSize = objectToScale.localScale;
while (counter < duration)
{
counter += Time.deltaTime;
objectToScale.localScale = Vector3.Lerp(startScaleSize, toScale, counter / duration);
yield return null;
}
isScaling = false;
}
}
Я пытался использовать al oop:
for (int i = 0; i < objectsToScale.Length; i++)
Но он масштабирует только первый объект в массиве.