- Home /
Going to sleep on this one... Help with an emitter array and loop
Hello everyone, I'm following a book called Unity 3.x Game Development essentials by Will Goldstone and I had a quick question about it. I've been trying for the past 2 hours to figure out why my fire will not emit particles at a certain part in the game (after i collect some matches). Oh yes, my problem is that when I do collect the matches and everything is well, upon colliding with my campfire, my particle system for my campfire will not emit the particles (which is a fire and smoke particle effect). I have them turned off on start (play on awake) but I should have them coded to where they will start as soon as I collect some matches and collide with the campfire. Fortunately, the sound plays and the matchGUI is destroyed, the code near the end of the function, so that's good, but the particles will just not emit. My first assumption is that this book is just too outdated, which it is, but everything seems coded correctly. So I was wondering that maybe it is just outdated, and that it is a possibility that I should be using some other code.
Not sure, but here is the function I'm using to make the array and for loop.
void LightFire (GameObject campfire)
{
ParticleEmitter [] fireEmitters;
fireEmitters = campfire.GetComponentsInChildren ();
foreach (ParticleEmitter emitter in fireEmitters)
{
emitter.emit = true;
}
campfire.audio.Play();
Destroy (matchGUI);
haveMatches = false;
}
So in other words, I'm using an array to carry out the same set of commands on multiple objects. This function needs to light the campfire by enabling the emit property of both of my particle systems that are childs of my "campfire" gameobject. Which is the reason I use the GetComponentsInChildren command. I begin my establishing a local array inside my custom function called LightFire. I populated the array with both of the particle emitter components. Then I used a for loop to repeat through this array and perform a command on the emitters in the array. I established a variable called emitter which is passed each entry in the fireEmitters array each time the loop runs. This is then used to address the emit parameter of the Particle Emitter component, setting it to true. Then I have it playing an audioclip, and also destroying a gui and setting my haveMatches boolean to false. Those latter three all work, but the worthless particles will not emit, lol yeeeesh.
Okay guys, sorry if this was very long, but I'm very tired now and I was just really hoping to be as thorough as I possibly could so that everything is clear cut. ANY help would be super awesome, and I know you guys are! :D Good luck, and thank you for dealing with my noviceness! :)
Edit: Eh, I'm trying to format the code to put it into divided columuns but it's just not having it today :/ lol
Re-Edit: HA I GOT IT!
Please EDIT and dramatically shorten your question.
Cut to the absolute core issues. I genuinely want to help but nobody has time to read that much. (Well done on the formatting)
Answer by AlucardJay · Apr 08, 2013 at 06:59 AM
Check the video that updates this part : http://www.youtube.com/watch?v=xnK5g2z9ESQ
Awesome! I didnt think to search for this on Youtube lol, thank you so much man!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Array weapons Wheel scroll switch 1 Answer
Move one of the objects selected from array ? 1 Answer
Error when trying to set variable with array 1 Answer
Help with Array script 1 Answer