Search Unity

Only set particle position and rotation in script

Discussion in 'Scripting' started by Hertzole, Nov 17, 2018.

  1. Hertzole

    Hertzole

    Joined:
    Jul 27, 2013
    Posts:
    422
    Hello

    I'm trying to make some bullet decals and I want to only set the particle's position and rotation through a script and leave size and color to the particle system itself. But I can't find a way to make the particle system give me the "proper" sizes and colors.

    Here is my current code:
    Code (CSharp):
    1. decalParticles = new ParticleSystem.Particle[bulletDecals.main.maxParticles];
    2. decalData = new BulletDecalData[bulletDecals.main.maxParticles];
    3. for (int i = 0; i < bulletDecals.main.maxParticles; i++)
    4. {
    5.     decalData[i] = new BulletDecalData();
    6. }
    7.  
    8. if (decalParticleDataIndex >= bulletDecals.main.maxParticles)
    9.     decalParticleDataIndex = 0;
    10.  
    11. decalData[decalParticleDataIndex].position = hit.point + (hit.normal * 0.01f);
    12. Vector3 particleRotationEuler = Quaternion.LookRotation(hit.normal).eulerAngles;
    13. particleRotationEuler.z = Random.Range(0f, 360f);
    14. decalData[decalParticleDataIndex].rotation = particleRotationEuler;
    15.  
    16. decalParticleDataIndex++;
    17.  
    18. for (int i = 0; i < decalParticles.Length; i++)
    19. {
    20.     decalParticles[i].position = decalData[i].position;
    21.     decalParticles[i].rotation3D = decalData[i].rotation;
    22.     //decalParticles[i].startSize = decalData[i].size;
    23.     //decalParticles[i].startColor = decalData[i].color;
    24. }
    25.  
    26. bulletDecals.SetParticles(decalParticles, decalParticles.Length);
    This sets the position and rotation correctly, but I need a way to calculate the size and color (the commented lines). I could do it myself but when I did it, some random colors didn't mix like they do with the particle system, and all of these curves, I don't know how they work.

    I've also tried to emit one particle for every decal but that applied lifetime, speed, and all the other stuff I don't want with bullet decals and just resulted in weird behavior.

    So, is there any way to make the particle system just take of size and color for me so I can just set the position and rotation?