private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Enemy") { if (invincible == true) // if player is experiencing invincible power up game loss is skipped { } else { levelData.gameLost(); GameObject particles = Instantiate(deathParticles, transform.position, Quaternion.identity); particles.GetComponent <Renderer>().material = GameObject.FindWithTag("Player").GetComponent <SpriteRenderer>().material; // sets the colour of death particles to match player material particles.GetComponent <ParticleSystemRenderer>().material = GameObject.FindWithTag("Player").GetComponent <SpriteRenderer>().material; // sets the colour of death particles to match player material Instantiate(deathAudio, transform.position, Quaternion.identity); Destroy(gameObject); } } }