Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ParticleAnimator via script

Discussion in 'Scripting' started by agentcooper, Apr 23, 2008.

  1. agentcooper

    agentcooper

    Joined:
    Jan 19, 2008
    Posts:
    98
    hi guys,

    how do I access a ParticleAnimator via a script? So far I have this:


    Code (csharp):
    1. //sets the rain on or off
    2.             var rain = this.gameObject.FindWithTag("playerRain");
    3.             rain.particleEmitter.emit = weatherTypes[i].particleEmit;
    4.  
    5.  
    Now I would like to be able to set the force as well, but I cannot figure out how to access the ParticleAnimator.

    Cheers!
     
  2. Charles Hinshaw

    Charles Hinshaw

    Joined:
    Feb 6, 2008
    Posts:
    1,070
  3. Samantha

    Samantha

    Joined:
    Aug 31, 2005
    Posts:
    609
    You'll have to make a reference to the Particle Animator component that's attached to the GameObject.

    Code (csharp):
    1. //sets the rain on or off
    2.  
    3. // FYI this.gameObject is unnecessary and a bit slow
    4. var rain = FindWithTag("playerRain");
    5. rain.particleEmitter.emit = weatherTypes[i].particleEmit;
    6.  
    7. // get a reference to the particle animator
    8. var rainPA = rain.GetComponent (ParticleAnimator);
    9. rainPA.force = -Vector3.up * someFloat;
    10.  
     
  4. agentcooper

    agentcooper

    Joined:
    Jan 19, 2008
    Posts:
    98
    Thanks guys! Actually just after posting this, I had a flash of genius which lead me to the same conclusion as Mr Kalman!

    I then lost my interinet connection for a couple of days so couldnt get back to you! :(

    Thanks for the support tho :)