void Update()
{
bool end=false;
Camera_BillboardingMode();
// Calculate index
float index = (Time.time-startTime) * framesPerSecond;
if (!isOneShot && life>0 && (Time.time -lifeStart)> life){
effectEnd=true;
}
if ((index<=spriteCount || !isOneShot ) && !effectEnd ){
if (index >= spriteCount){
startTime = Time.time;
index=0;
if (addColorEffect){
currentColor = colorStart;
meshRender.material.SetColor("_Color", currentColor);
}
currentSize = sizeStart;
myTransform.localScale = currentSize;
if (randomRotation){
currentRotation = Random.Range(-180.0f,180.0f);
}
else{
currentRotation = rotationStart;
}
}
// repeat when exhausting all frames
index = index % (uvAnimationTileX * uvAnimationTileY);
// Size of every tile
Vector2 size = new Vector2 (1.0f / uvAnimationTileX, 1.0f / uvAnimationTileY);
// split into horizontal and vertical index
float uIndex = Mathf.Floor(index % uvAnimationTileX);
float vIndex = Mathf.Floor(index / uvAnimationTileX);
// build offset
Vector2 offset = new Vector2 (uIndex * size.x , 1.0f - size.y - vIndex * size.y);
GetComponent<Renderer>().material.SetTextureOffset ("_MainTex", offset);
GetComponent<Renderer>().material.SetTextureScale ("_MainTex", size);
GetComponent<Renderer>().enabled = true;
}
else{
effectEnd = true;
GetComponent<Renderer>().enabled = false;
end = true;
if (soundEffect){
if (soundEffect.isPlaying){
end = false;
}
}
if (addLightEffect && end){
if (GetComponent<Light>().intensity>0){
end = false;
}
}
if (end){
Destroy(gameObject);
}
}
// Size
if (sizeStart != sizeEnd){
myTransform.localScale += sizeStep * Time.deltaTime ;
}
// Light effect
if (addLightEffect && lightFadeSpeed!=0){
GetComponent<Light>().intensity -= lightFadeSpeed*Time.deltaTime;
}
// Color Effect
if (addColorEffect){
currentColor = new Color(currentColor.r + colorStep.r * Time.deltaTime,currentColor.g + colorStep.g* Time.deltaTime,currentColor.b + colorStep.b* Time.deltaTime , currentColor.a + colorStep. a*Time.deltaTime);
meshRender.material.SetColor("_TintColor", currentColor);
}
}