Our goal is to create a huge amount of object and orientate them along a surface in 3d space. Since this application should run on an android tablet and instantiating anything more then 1000 - 2000 objects at runtime is not really feasible we decided to go for a mesh particle system and place the particles via code.
This works like a charm! Unity Mesh particle renderer is ridiculously fast and rendering large amounts of objects even on low end machines is no problem.
BUT:
We’d also like to have control over the orientation of our particles but no matter what we try it doesn’t seem to work. The undocumented variable axisOfRotation SHOULD set the rotation of the particle but it doesn’t seem to do anything at all. Is this a Unity bug or am I missing something really obvious here?
Here is some code:
using UnityEngine;
using System.Collections;
public class particleHandler : MonoBehaviour {
public Vector2 size = new Vector2(100, 100);
private ParticleSystem particleSystem;
private ParticleSystem.Particle[] particles;
void Start () {
particleSystem = GetComponent<ParticleSystem>();
particles = new ParticleSystem.Particle[(int) (size.x * size.y)];
for(int x=0;x<size.x;x++) {
for(int y=0;y<size.y;y++) {
newPin(new Vector3(x,0,y));
}
}
StartCoroutine(littleEffect() );
}
void newPin (Vector3 v) {
particleSystem.Emit(v, Vector3.zero, 0.5f, Mathf.Infinity, Color.blue);
}
IEnumerator littleEffect () {
yield return new WaitForSeconds(3f);
int length = particleSystem.GetParticles(particles);
int i = 0;
while (i < length) {
particles[i].color = Color.red;
particles[i].axisOfRotation = Random.rotation * Vector3.forward; //why wont you work!?
i++;
particleSystem.SetParticles(particles, length);
yield return null;
}
}
}