public void Kill(string type, PB_Enemy e) // Kills an enemy in different ways { if (type == "Jump") { e.Damage("Jump"); Jump(10.0f, true, true); SoundController.instance.Play(_bounceSound, .5f, UnityEngine.Random.Range(1.0f, 1.25f)); } else if (type == "Dive") { _cam.Shake(.25f); Jump(15.0f, true, true); e.Damage("Dive"); SoundController.instance.Play(_bounceHardSound, .5f, UnityEngine.Random.Range(1.0f, .75f)); _hitFX.transform.position = e.transform.position + (Vector3) new Vector2(.1f, .25f);; _hitFX.Play(); } else if (type == "Slash") { e.Damage("Slash"); SoundController.instance.Play(_bounceSound, .5f, UnityEngine.Random.Range(1.0f, 1.25f)); } _featherFX.transform.position = e.transform.position; _featherFX.Emit(10); // Feathers splash when enemy dies }
//Checks if player collides with other colliders public IEnumerator OnCollisionEnter2D(Collision2D col) { if (PB_GameController.instance._mode == "Game") { if (col.gameObject.tag == "Ground") // Collides with colliders in the layer named Ground { if (!_diving) { _anim.Play("Run"); // Plays the running animation clip SoundController.instance.Play(_landSound, .1f, UnityEngine.Random.Range(.5f, .75f)); _landFX.transform.position = transform.position; _landFX.Play(); } else { _stunned = true; // Stuns the player if diving into the ground _stunTimer = 1.0f; // Player is stunned for 1 second _anim.Play("Stunned"); // Play stun animation _cam.Shake(.5f); // Shake the camera SoundController.instance.Play(_crashSound, .5f, UnityEngine.Random.Range(1.0f, .75f)); _crashFX.transform.position = transform.position; // Set FX position _crashFX.Play(); // Play FX } _canSwing = false; // Can only swing in the air _jumping = false; // Not jumping any more _diving = false; // Not diving } else if (col.gameObject.tag == "Enemy") //Collides with colliders in the layer named Enemy { PB_Enemy e = col.gameObject.GetComponent <PB_Enemy>(); if (e._type == "Regular") { if (_jumping) { _jumping = false; if (!_diving) { Kill("Jump", e); } else { Kill("Dive", e); } yield return(new WaitForSeconds(.01f)); _diving = false; } else { Death(); } } else if (e._type == "Flapping") { if (this._canSwing) { Death(); } else { Kill("Slash", e); Jump(5.0f, true, false); this._canSwing = true; } } else if (e._type == "Helmet") { if (_jumping) { _jumping = false; if (!_diving) { Jump(10.0f, true, true); SoundController.instance.Play(_helmSound, .5f, UnityEngine.Random.Range(.75f, 1.0f)); } else { _helmFX.transform.position = e.transform.position; _helmFX.Emit(1); _hitFX.transform.position = e.transform.position + (Vector3) new Vector2(.1f, .25f);; _hitFX.Play(); e._type = "Regular"; e._stunned = true; Jump(10.0f, true, true); e._anim.Play("Stunned"); _cam.Shake(.25f); SoundController.instance.Play(_helmSound, .5f, UnityEngine.Random.Range(1.25f, 1.5f)); } _diving = false; } else { Death(); } } else if (e._type == "Spiked") // Spike helmet enemies kills player { Death(); } } } }