- Home /
Question by
DevMerlin · Dec 27, 2020 at 08:04 PM ·
particlesmodulestexture atlas
Particles created in code ignore Texture Sheet Animation?
I'm using a modified version of the tutorial here:
http://guidohenkel.com/2018/05/endless_starfield_unity/ - which has been a BIG help to me before, in order to create clouds instead of stars.
This is actually mostly working. However, I've hit an odd stumbling block.
Texture Sheet Animation is turned on and filled out. However, it's seemingly ignoring it by only using the first sprite in the Sprites mode layout.
Do particles that are created in code ignore the overall settings?
Here's what I have thus far.
using UnityEngine;
public class CloudController : MonoBehaviour
{
public int MaxClouds = 100;
public float Cloudsize = 0.1f;
public float CloudsizeRange = 0.5f;
public float FieldWidth = 20f;
public float FieldHeight = 25f;
public float cloudSpeed = 0.005f;
float xOffset;
float yOffset;
ParticleSystem Particles;
ParticleSystem.Particle[] Clouds;
public Transform activeCamera;
void Awake()
{
Particles = GetComponent<ParticleSystem>();
}
private void Start()
{
generateClouds();
}
void generateClouds()
{
Clouds = new ParticleSystem.Particle[MaxClouds];
xOffset = FieldWidth * 0.5f;
yOffset = FieldHeight * 0.5f;
for (int i = 0; i < MaxClouds; i++) {
float randSize = Random.Range(CloudsizeRange, CloudsizeRange + 1f);
Clouds[i].position = GetRandomInRectangle(FieldWidth, FieldHeight) + transform.position;
Clouds[i].startSize = Cloudsize * randSize;
Clouds[i].startColor = Color.white;
}
Particles.SetParticles(Clouds, Clouds.Length);
}
private void Update()
{
for (int i = 0; i < MaxClouds; i++) {
Vector3 pos = Clouds[i].position + transform.position;
pos.x -= cloudSpeed;
if (pos.x < (activeCamera.position.x - xOffset)) {
pos.x += FieldWidth;
} else if (pos.x > (activeCamera.position.x + xOffset)) {
pos.x -= FieldWidth;
}
Clouds[i].position = pos - transform.position;
}
Particles.SetParticles(Clouds, Clouds.Length);
}
// GetRandomInRectangle
//----------------------------------------------------------
// Get a random value within a certain rectangle area
//
Vector3 GetRandomInRectangle(float width, float height)
{
float x = Random.Range(0, width);
float y = Random.Range(0, height);
return new Vector3(x - xOffset, y - yOffset, 0);
}
}
Am I missing something to make this work with the Texture Sheet Animation module?
Comment
Your answer
