- Home /
Coding a Particle System to play when a GameObject hits ground.
I'm trying write a script so that when my GameObject, preferably a character hits the ground, it plays the particle of dust kicking up when you land. Right now just to make sure it at least works with a character, I'm using the Tag "Player"
I'm using the OnTriggerEnter function as a start, but the play function of the particle system gives me the error "An instance of type 'UnityEngine.ParticleSystem' is required to access non static member 'Play'."
function OnTriggerEnter(col:Collider)
{
if(gameObject.tag == "Player")
{
ParticleSystem.Play;
}
}
The idea is to call this in the update function.
Answer by bdsaxxy · Apr 03, 2014 at 09:47 AM
well, instead of using particle.play();...you could use
Instantiate(particle, transform.position, transform.rotation);
public ParticleSystem particle; public Transform transform;
Instantiate(particle, transform.position, transform.rotation);
Answer by froYo · Feb 18, 2013 at 12:45 AM
Hey, The problem you seem to be having here is that you aren't referencing the particle you wish to use.
For example:
var particle : ParticleSystem;
function OnTriggerEnter(col:Collider)
{
if(gameObject.tag == "Player")
{
particle.Play;
}
}
Then you would drag the particle that you have created and want to play into the variable "particle" on the inspector.
Also you would need to set the particle to not play on awake so it doesn't play when you don't want it to.
Hope this helps :)
Thank You. I forgot you needed to declare a variable for a GameObject that you want to do something. $$anonymous$$y Problem now is that I don't know how to write the component that gets the Particle to play. ParticleSystem.Play didn't work
You need parenthesis after play, since it's a function. Like so:
particle.Play();
Your answer
Follow this Question
Related Questions
Particle System emits on Trigger Stay, in Unity 5 1 Answer
OnTriggerEnter behaving oddly?!? 1 Answer
Becoming parent after OnTriggerStay/Enter? 1 Answer
Won't Enter GetButton Statement 1 Answer
How do I make my platform not be jerky? 2 Answers