Smoke and Brick Color Same - Unity 5.6

Here’s the solution I ended up with to make the smoke and brick colors the same. Is this code ok. Is there a more efficient way to code the same effect with less lines of code?

   void HandleHits ()
    	{
    		timesHit++;
    		int maxHits = hitSprites.Length + 1;
    		if (timesHit >= maxHits) {
    			print(brickCount);
    			brickCount--;
    			levelManager.BrickDestroyed();
    			 
    			GameObject smokePuff = Instantiate(smoke, gameObject.transform.position, Quaternion.identity);
    			ParticleSystem ps = smokePuff.GetComponent<ParticleSystem>();
    			var ma = ps.main;
    			ma.startColor= gameObject.GetComponent<SpriteRenderer>().color;
    			Destroy (gameObject);
    			brickCount = brickCount++;
    		} else {
    			LoadSprites();
    		}
    	}

Thank you for the help!
-Todd

2 Likes
void HandleHits(){
	timesHit++;
	int maxHit = hitSprites.Length+1;
	
	if (timesHit>=maxHit){
		brickCount--;
		levelManager.brickDestroyed();
		GameObject smokeClone = Instantiate(smoke, transform.position, Quaternion.identity);
		var sC = smokeClone.GetComponent<ParticleSystem>().main;
		sC.startColor = gameObject.GetComponent<SpriteRenderer>().color;
		Destroy(gameObject);
	}else{
		LoadSprites();
	}
}

Hi,
I basically did, what you, except I used one less line :slight_smile:

Regards,
Daniel

1 Like

Privacy & Terms