Hello all,
I am trying to get some particle effects on the main character of my game. There are 2 different ways that I have tried this and I have run into problems with both. Perhaps someone can help me come up with a better method or improve one of my existing ones?
What I’m trying to do is quite simply actually. Whenever I press a button, particles should emit from the player’s body, but here’s the catch: they should follow him when he moves. Here are the two ways I have tried, and the problems with each one:
- Attach a particle system prefab as a child to the player.
After I have attached it to the player, I do not know how i can get it to “turn on” or “turn off” in the scripts. I have tried using:
sprayer.particleEmitter.particleSystem.Play();
But this results in an error that says that I do not have a particle emitter attached. I don’t know how I am supposed to access the particle system otherwise because although I have declared sprayer as a particle system, intellisense does not give me any options that have to do with the particlesystem.
- Simply instantiate the particle system at the player’s position.
The reason that this fails is because the particle system stays in the place that it was instantiated. I have tried attaching a script to the system that sets its position to the player’s transform.position. But this does not work because prefabs cannot reference an object that is inside the scene already.
Recently, I am also getting an error similar to this one:
Any other advice on playing around with particle systems would be greatly appreciated. Thanks in advance!