Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2002
    Location
    Los Angeles, CA
    Posts
    3,607

    GetComponent and ParticleSystem

    I may be missing something obvious, but last night i couldn't figure out how to gain access to ParticleSystem attached to some object.

    i have two objects: xform1 and xform2
    xform1 has a script attached
    xform2 has a ParticleSystem (shuriken) attached
    i want to be able to trigger particle emission from the xform1's script when some button is pressed.
    The problem is that i cannot figure out how to access the ParticleSystem on the other object - xform2
    Tried so many things (getComponent variations) but always get null pointers.

    var go : GameObject;
    private var ps : ParticleSystem;

    Tried many variations of the two lines below. No syntax errors, just null pointers.
    ps = go.GetComponent(ParticleSystem);
    ps = go.GetComponent("MyParticleSystem");
    etc ...

    Also the component class has particleSystem attribute that should give me the particle system attached to the game object. But not sure how to make use of that too.

    Can somebody provide an example how to gain access to a ParticleSystem located on an object from script attached to another object ?

    Thanks.

  2. #2
    Join Date
    Sep 2004
    Location
    Mesa, Arizona
    Posts
    421
    Maybe the problem is that your variable 'go' is not being properly set to the xform2 object? I would assume you should have something like this:

    go = GameObject.Find("xform2");

    If that looks like what you have I would still double check with some debug logs or something that it is the proper object. That's the only thing I could think of without seeing more code.
    "You don't stop laughing because you grow old. You grow old because you stop laughing."

  3. #3
    Join Date
    Apr 2007
    Location
    Seattle
    Posts
    214
    Try it this way. It works for me when I do it like this.
    Code:
    go.GetComponent<ParticleSystem> as ParticleSystem

  4. #4
    Join Date
    Apr 2002
    Location
    Los Angeles, CA
    Posts
    3,607
    Thanks for the help guys, I'll give these a go!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •