I have a script that instantiates a prefab when a projectile first enters a collider, and then increases the scale of that prefab for each of the next four projectiles that enter the collider using Lerps.
The interpolation is fine the first time this code runs. But each time after that there is a delay in the first Lerp function. How do I fix this awkward pause?
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Projectile"))
{
catchCount++;
}
}
void CatchAndRelease()
{
proj = GameObject.Find("ReleaseObj(Clone)");
switch (catchCount)
{
case 0:
if(isInstantiated == true)
{
catchCount = 0;
}
break;
case 1:
if(isInstantiated == false)
{
Instantiate(releaseObj, transform.position, Quaternion.identity, gameObject.transform.parent);
isInstantiated = true;
}
break;
case 2:
Vector3 scaleUp = new Vector3(1.5f, 1.5f, 1.5f);
proj.transform.localScale = Vector3.Lerp(proj.transform.localScale, scaleUp, Time.deltaTime);
break;
case 3:
Vector3 scaleUp2 = new Vector3(2f, 2f, 2f);
proj.transform.localScale = Vector3.Lerp(proj.transform.localScale, scaleUp2, Time.deltaTime);
break;
case 4:
Vector3 scaleUp3 = new Vector3(2.5f, 2.5f, 2.5f);
proj.transform.localScale = Vector3.Lerp(proj.transform.localScale, scaleUp3, Time.deltaTime);
break;
case 5:
Vector3 scaleUp4 = new Vector3(3f, 3f, 3f);
proj.transform.localScale = Vector3.Lerp(proj.transform.localScale, scaleUp4, Time.deltaTime);
break;
case 6:
if(isInstantiated == false)
{
catchCount = 0;
}
else
{
catchCount = 6;
}
break;
}
Still quite new to C# and any help or advice is greatly appreciated!