[HELP] Making the puffs of smoke match the bricks

ok…so last time I got to this point I broke my game (lol) now ive remade it and am making the puffs appear but they are not changing colour…i looked at what was shown but it dosnt seem to have any affect…ALSO when i have it in the position that is shown in the videos my blocks stop breaking…

void HandleHits (){

	timesHit = timesHit +1;
	int maxHits = hitSprites.Length + 1;
	
	if (timesHit >= maxHits){
		breakableCount--;
		levelManager.BrickDestroyed();
		GameObject smokePuff = Instantiate (smoke, transform.position, Quaternion.identity) as GameObject;
		smokePuff.particleSystem.startColor = gameObject.GetComponent<SpriteRenderer>().color
		Destroy (gameObject);
	
		AudioSource.PlayClipAtPoint (smash,transform.position);
		;
	}	else{
		LoadSprites();
	}

}

ive tried changing the position of the smoke puff code and this allows the bricks to break again but still no colour change…any ideas…??

Not sure which version of Unity you are using, I think it was a more recent version from memory, but try this slight change in your HandleHits method;

        smokePuff.GetComponent<ParticleSystem>().startColor = gameObject.GetComponent<SpriteRenderer>().color;

You also have a rogue semi-colon at the end of the first if statement code block, and one missing from the line in question which changes the colour of the smoke puff.

1 Like

ah yup the extra and missing colons were from cutting and pasting trying different spots cheers! its one irritating bit of cutting and pasting in mono develop for me.

im using unity 4 some…8 i think??

OK! now…whats happened is ive put your code in and its given me an error message i wasnt getting before…the prefabed smoke didnt actually have a particle effect attached…(which is odd…because it was still giving me those effects across levels so not sure what is up with that) but ive reattached the particles and now with the original code and the new code i get blue smoke! cheers!

the only thing is i am still getting background white smoke behind it…in the video he only gets the coloured smoke…do you know how to change this?

1 Like

all good i just worked it out!
having the emission switch turned on makes there be a background of white smoke!!

cheers for the help dude!! XD

OH and in another post i asked about multiselecting in the heirarchy and it IS covered in the videos i noticed after rebuilding my block breaker you click the first one you want and go to the last one you want and hold shift while you select it and it selects everything between them XD

1 Like

One last question dude
Do you know how to reduce how long the puffs last for…?? i know this may seem like a silly question but ive tried reducing the start and duration times down to 1 and even .1 but they seem to last for ages…

1 Like

Hi,

Ah, older version but glad you have it sorted.

Regarding the duration, it should simply be the duration variable on the particle system.

Obviously I can’t see what you are changing, but if you happen to have an instance in the scene and you are changing that, bear in mind that will be different from your prefab, which is what you will have dragged into the Inspector for the smokePuff reference.

If I were you I would try a separate little test. Create an empty scene. Drag your smokePuff prefab into it. Check the duration of the smokePuff prefab, then run the scene, count in your head in seconds and see if the duration is about right. Note, make sure you have looping turned off or you’ll be counting for some time :wink:

If it seems right, change the value of the prefab to something else, perhaps 10 seconds. Check the instance in the test scene and see if it has the new value, if not, delete it and drag another in. Run the same test. Assuming you count to about 10 seconds you know your prefab is good. In which case, perhaps in your actual game scene you have not referenced the actual thing you are changing the values on (e.g. instance rather than prefab).

Hope this helps :slight_smile:


See also;

1 Like

Ok cheers mate much appreciated…
I readded the prefab into the scene and compared the behaviour of the smoke anchored in the bricks and that of the added prefab and there was a difference…so i deleted my prefab and used the newly added game object to make a new prefab (weird because they were all from the original same prefab…so…dont understand why the different behaviour) and now my bricks arent smoking forever :smiley:
another anomally is that creating the original prefab with the emission switched on stopped the colours changing but was all good once it was switched off then back on (i hear this is a common IT problem “well sir…did you try turning it off then back on again?”) - this didnt seem to happen when i created the new prefab…

bit odd but i am there with your assistance :smiley:

1 Like

Glad to hear you have it all sorted now Blake - well done :slight_smile:

1 Like

these problems are getting less and less frustrating…which is a good sign…i may be in fact learning here lol

1 Like

Privacy & Terms