making a delay on particle collider spawn?
I made a particle effect with collision. However, I would like the particle colliders to spawn a little later than the particle effects, so that the particle does not have colliders for the first few moments of its lifespan. how can I do this?
Now i see what you are trying to do. A Particle Collisionmodul is not a Collider Component! So you are trying to access something, thats not attached to your scriptholder. Use the following code :
ParticleSystem particlesystemVariable ;
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[particlesystemVariable .particleCount];
void Start()
{
particlesystemVariable = gameObject.GetComponent<ParticleSystem> ();
StartCoroutine(DelayCollider());
}
IEnumerator DelayCollider()
{
for (int i = 0; i < particlesystemVariable .particleCount;i++){
particles [i].velocity = 20f;
}
var collisionVariable = particlesystemVariable .collision;
collisionVariable .enabled = false;
yield return new WaitForSeconds(delayTime);
var collisionVariable = particlesystemVariable .collision;
collisionVariable .enabled = true;
}
// Update is called once per frame
void Update()
{
}
That was very nice of you,
However, I get error; "the name "particlesystemVariable" does not exist in the current context. and
a local variable or function named "collisionVariable" is already defined in this scope
What am I supposed to do with those?
Uff, :D You really have no idea, do you? "particlesystemVariable was an example, of a Variable, that you need to declare. Like : ParticleSystem particlesystemVariable ;
. I edit the example i sent you.
Answer by BenWiller1989 · Sep 05, 2020 at 09:01 PM
Use a Coroutine and set the Collider.enabled = true or false?
thanks. I am currently trying that. however it doesnt work. I am no programmer, so no surprise. I am getting an error, saying there is no "Collider" attached to the particle. the particle generates its own colliders, so I have no idea how to access them through the script?
{ public float delayTime = 3f; private Collider col;
void Start()
{
StartCoroutine(DelayCollider());
}
IEnumerator DelayCollider()
{
col = GetComponent<Collider>();
col.enabled = false;
yield return new WaitForSeconds(delayTime);
col.enabled = true;
}
// Update is called once per frame
void Update()
{
}
}
Well, did you attach a ColliderComponent to the scriptholder? Can you send a screenshot of the Inspector of the scriptholder?
I made the particle generate the Colliders in the inspector. And I added the script to the particle