- Home /
How to control World Particle Collider through script
Is there a way to add a world particle collider to a particle system through script. AddComponent(???);
If there's not a way to add it at runtime is there a way to enable/disable it?
Answer by Justin Warner · Apr 04, 2011 at 12:39 AM
Add it to the actual particle effect, then you can enable/disable it...
Use get component
http://unity3d.com/support/documentation/ScriptReference/GameObject.html
To get the component, and just .enable = false/true on which you want..
Should work =). Good luck!
Code:
function Update () {
if(Input.GetKeyDown("w")){
var test = gameObject.GetComponent("WorldParticleCollider");
print(test);
}
}
Preferably I'd like to create it in script with addComponent but I went ahead and added it to the prefab to try and control it that way. I can't seem to find out how to enable/disable it though. If I try to getComponent(Collider) it says there's not a collider attached. There's not an option, that I can find, for getting a WorldParticleCollider. Do you know the correct syntax for this?
Edited and it works... So, that test is a gameobject, so now you can do .enable = false/true...
gameObject.GetComponent("WorldParticleCollider") It doesn't work at all.