I have a game object that grows for a certain amount of time, then once it reaches a set size it duplicates itself. However… I’d like the duplicated object to be reset back to the original size (so it can go through the grow process again before duplicating itself)
#pragma strict
public var circleRadius : float;
public var waitTime : float = 2f;
private var hasDuplicated : boolean = false;
private var fullyGrown : boolean = false;
function Update()
{
if(fullyGrown == false)
{
if(transform.localScale.x >= 3.0 && transform.localScale.y >= 3.0 && transform.localScale.z >= 3.0 )
{
fullyGrown = true;
StartCoroutine(WaitAndDuplicate());
}
else
if(transform.localScale.x < 3.0 && transform.localScale.y < 3.0 && transform.localScale.z < 3.0 )
{
transform.localScale += Vector3(0.001,0.001,0.001); // Increase object size by .01 per frame
}
}
}
function WaitAndDuplicate()
{
if(hasDuplicated == false)
{
yield WaitForSeconds(waitTime); var randomOffset : Vector3 = Random.insideUnitCircle * circleRadius; randomOffset = Vector3(randomOffset.x, randomOffset.z, randomOffset.y); Instantiate(gameObject, transform.position + randomOffset, transform.rotation);
hasDuplicated = true;
}
}
At the moment, the game object grows to full size, waits 2 seconds then duplicates itself. The trouble is the duplicate is already fully grown (which I don’t want)
How do I get each new duplicate to start off at the original size?