/// <summary> /// Triggered when the shark collides with the player /// </summary> /// <param name="collidingObject">the object that collides with our shark.</param> protected virtual void OnTriggerEnter2D(Collider2D collidingObject) { // we verify that the colliding object is a PlayableCharacter with the Player tag. If not, we do nothing. PlayableCharacter player = collidingObject.GetComponent <PlayableCharacter>(); if (player == null) { return; } if (collidingObject.tag != "Player") { return; } // we shake the camera - uncomment these two lines if you want to add a shake effect when the shark collides with your player. I thought it was a bit too much. //Vector3 ShakeParameters = new Vector3(1.5f, 0.5f, 1f); //_camera.Shake(ShakeParameters); // we instantiate an explosion at the point of impact. GameObject explosion = (GameObject)Instantiate(Explosion); explosion.transform.position = new Vector3(transform.GetComponent <Renderer>().bounds.min.x, transform.GetComponent <Renderer>().bounds.center.y, 0); CorgiTools.UpdateAnimatorBool(explosion.GetComponent <Animator>(), "Explode", true); // we turn the object inactive so it can be instantiated again gameObject.SetActive(false); }
/// <summary> /// On fixed update /// </summary> protected override void FixedUpdate() { // we send our various states to the animator. UpdateAnimator(); // if jumping is true, we've just passed this info to the animator and reset it. if (_jumping) { _jumping = false; } // if the dragon becomes grounded, we instantiate an explosion and kill it if (IsGrounded) { // we shake the camera //Vector3 ShakeParameters = new Vector3(0.3f, 0.2f, 0.3f); //_camera.Shake(ShakeParameters); GameObject explosion = (GameObject)Instantiate(Explosion); explosion.transform.position = transform.GetComponent <Renderer>().bounds.center + 1 * Vector3.down; CorgiTools.UpdateAnimatorBool(explosion.GetComponent <Animator>(), "Grounded", _grounded); LevelManager.Instance.KillCharacter(this); } // if we're supposed to reset the player's position, we lerp its position to its initial position ResetPosition(); }
/// <summary> /// Updates all mecanim animators. /// </summary> protected override void UpdateAllMecanimAnimators() { CorgiTools.UpdateAnimatorBool(_animator, "Grounded", IsGrounded); CorgiTools.UpdateAnimatorFloat(_animator, "VerticalSpeed", _rigidbodyInterface.Velocity.y); CorgiTools.UpdateAnimatorBool(_animator, "Jumping", _jumping); CorgiTools.UpdateAnimatorBool(_flameAnimator, "Jumping", _jumping); }
/// <summary> /// Updates all mecanim animators. /// </summary> protected virtual void UpdateAllMecanimAnimators() { CorgiTools.UpdateAnimatorBool(_animator, "Grounded", IsGrounded); CorgiTools.UpdateAnimatorFloat(_animator, "VerticalSpeed", _rigidbodyInterface.Velocity.y); }