- Home /
Question by
blutsgewalt · Feb 26, 2017 at 01:23 PM ·
c#scripting problemparticles
Texture Sheet Animation - Set Row Index for each Particle via Script
Hey,
i'm trying to use one ParticleSystem to emit particles with different styles. All praticles are generates via code and everything works as expected except of the tiling. All particles always have the same Tile which is the last value of the line anim.rowIndex = i % noOfTiles;
The code runs once on Start()
public void Generate(int noOfObjects, int noOfTiles)
{
List<Vector3> spawnLocations = FancyRandomFunction();
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[noOfObjects];
ParticleSystem.TextureSheetAnimationModule anim = ps.textureSheetAnimation;
for (int i = 0; i < noOfObjects; i++)
{
particles[i] = new ParticleSystem.Particle();
particles[i].position = spawnLocations[i];
particles[i].remainingLifetime = 100f;
particles[i].startSize = 1f;
particles[i].startLifetime = 100f;
particles[i].startColor = Color.white;
anim.rowIndex = i % noOfTiles; // <--- alternate RowIndex
}
ps.SetParticles(particles, noOfObjects);
}
Is there any way to force different tiles for each particle from code?
Comment
Answer by DungDajHjep · Apr 04, 2017 at 05:27 AM
i found a trick to do this
first particle system inspector set use randomRow = true;
and in code change numTilesY instead rowIndex
public void PlayEmitAllTextureSheet()
{
for (int i = 0; i < listParticle.Length; i++)
{
//listParticle[i].m_Particle.Play();
for (int j = 0; j < listParticle[i].emitCount; j++)
{
var textureSheetAnimation = listParticle[i].m_Particle.textureSheetAnimation;
textureSheetAnimation.numTilesY = j + 1;
//textureSheetAnimation.rowIndex = j;
//Debug.Log(textureSheetAnimation.rowIndex + " " + textureSheetAnimation.numTilesY);
listParticle[i].m_Particle.Emit(1);
}
}
}
Hello, I'Ve tried this solution but when I play the game, the texture displayed contains all the rOws