I’m attempting to create a delay in the script start so not all my objects start at the same pulsing at the same time. All my script does is create a pulsing effect that I’ve added to all my prefab objects. I then spawn all the objects at random within my map.
I’ve attempted to do what I found on unity’s API but alas, to no end.
void Start()
{
shrinking = true;
slowDown = false;
new WaitForSeconds(Random.Range(0,5);
}
here is the script as a whole
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DNAPulse : MonoBehaviour
{
public float targetScale = 0.5f;
public float shrinkSpeed = 0.3f;
public float enlargeSpeed = 0.5f;
public float slowEffect = 0.05f;
private bool shrinking;
private bool slowDown;
void Start()
{
shrinking = true;
slowDown = false;
}
void Update()
{
if (shrinking)
{
transform.localScale -= Vector3.one * Time.deltaTime * shrinkSpeed;
//if (transform.localScale < Vector3.one)
Debug.Log(transform.localScale.x);
if (transform.localScale.x < targetScale)
{
shrinking = false;
}
}
else if (!slowDown)
{
transform.localScale += Vector3.one * Time.deltaTime * enlargeSpeed;
if (transform.localScale.x > targetScale * 2)
slowDown = true;
}
if (slowDown)
{
transform.localScale += Vector3.one * Time.deltaTime * slowEffect;
if (transform.localScale.x > targetScale * 2.2)
{
slowDown = false;
shrinking = true;
}
}
}
}