public void OnCollisionEnter2D(Collision2D coll) { if (flattened || bloody) { return; } RockSpecial rock = coll.gameObject.GetComponent <RockSpecial>(); if (rock != null && rock.rocking) { Destroy(gameObject); } else if (!flattened) { Player player = coll.gameObject.GetComponent <Player>(); if (player != null) { player.Kill(); bloody = true; this.spriteRenderer.sprite = Resources.Load <Sprite>("Sprites/Environment/" + this.spriteRenderer.sprite.name + "_Blood") as Sprite; } } if (!bloody) { flattened = true; GetComponent <Collider2D>().isTrigger = true; } }
// Called on Collision public void OnCollisionEnter2D(Collision2D coll) { // someone has already died here - let no more die here if (bloody) { return; } if (Vector2.Dot(coll.contacts[0].normal, -Vector2.up) > 0.2f) { // let's see if the thing colliding with us has a RockSpecial RockSpecial rock = coll.gameObject.GetComponent <RockSpecial>(); if (rock != null && rock.rocking) { ((GameObject)Instantiate(this.particlePrefab, transform.position + Vector3.back * 2f, particlePrefab.transform.rotation)) .GetComponent <DestroyParticlesOnFinish>().followTarget = transform; Destroy(this.gameObject); // if it does, and it's active, the spike will blow up! } // if it doesn't have a rock special, we will die here else { // Kill player Player player = coll.gameObject.GetComponent <Player>(); if (player != null) { player.Kill(); bloody = true; this.spriteRenderer.sprite = Resources.Load <Sprite>("Sprites/Environment/" + this.spriteRenderer.sprite.name + "_Blood") as Sprite; } } } }