Пример #1
0
        /// <summary>
        /// Updates the shadow's size and position at every frame
        /// </summary>
        protected virtual void Update()
        {
            // vertical raycast below the agent
            _hit = CorgiTools.CorgiRayCast(transform.position, Vector2.down, _rayLength, GroundMask, true, Color.red);

            if (_hit)
            {
                _shadow.GetComponent <Renderer>().enabled = true;
                // updates the shadow's position according to the hit
                _shadow.transform.position  = new Vector2(_hit.point.x, _hit.point.y);
                _shadow.transform.position += ShadowOffset;

                // handles horizontal offset based on the ground/object distance.
                float distance = _shadow.transform.position.y - transform.position.y + GetComponent <Renderer>().bounds.size.y / 2;
                _shadowOffsetBasedOnHeight  = (ShadowMaxHorizontalDistance / (Mathf.Abs(MaximumVerticalDistance / distance))) * Vector3.right;
                _shadow.transform.position += _shadowOffsetBasedOnHeight;

                // prevents the shadow from rotating
                _shadow.transform.rotation = Quaternion.identity;
                // updates the size of the shadow based on the distance between the agent and the ground
                _shadow.transform.localScale = _initialScale / (_initialScale.x + Mathf.Abs(distance / 2));
            }
            else
            {
                // if the raycast didn't hit anything (the object is not above solid ground), we just hide the shadow
                _shadow.GetComponent <Renderer>().enabled = false;
            }
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <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();
        }
Пример #4
0
 /// <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);
 }
Пример #5
0
 /// <summary>
 /// Creates the initial shadow
 /// </summary>
 protected virtual void Initialize()
 {
     // we throw a raycast below the character and position the shadow accordingly
     _hit    = CorgiTools.CorgiRayCast(transform.position, Vector2.down, _rayLength, GroundMask, true, Color.red);
     _shadow = (GameObject)Instantiate(ShadowPrefab, _hit.point, Quaternion.identity);
     _shadow.transform.parent = this.transform;
     _initialScale            = _shadow.transform.localScale;
 }
Пример #6
0
        protected virtual void Disappear()
        {
            Color newColor = new Color(0, 0, 0, 0);

            StartCoroutine(CorgiTools.FadeImage(InstructionsPanel, FadeDuration, newColor));
            StartCoroutine(CorgiTools.FadeText(InstructionsText, FadeDuration, newColor));
            Invoke("DestroyInstructions", FadeDuration);
        }
Пример #7
0
        // this method initializes all essential elements
        protected virtual void Initialize()
        {
            _rigidbodyInterface = GetComponent <RigidbodyInterface> ();
            _animator           = GetComponent <Animator>();

            if (_rigidbodyInterface == null)
            {
                CorgiTools.DebugLogTime("You need a rigidbody interface");
                return;
            }
        }
Пример #8
0
 /// <summary>
 /// Fades the fader in or out depending on the state
 /// </summary>
 /// <param name="state">If set to <c>true</c> fades the fader in, otherwise out if <c>false</c>.</param>
 public virtual void FaderOn(bool state, float duration)
 {
     Fader.gameObject.SetActive(true);
     if (state)
     {
         StartCoroutine(CorgiTools.FadeImage(Fader, duration, new Color(0, 0, 0, 1f)));
     }
     else
     {
         StartCoroutine(CorgiTools.FadeImage(Fader, duration, new Color(0, 0, 0, 0f)));
     }
 }
Пример #9
0
        // On enable, we cast rays above and below the object to check for obstacles
        protected virtual void OnEnable()
        {
            RaycastHit2D raycastUpwards   = CorgiTools.CorgiRayCast(transform.position, Vector2.up, RaycastLength, 1 << LayerMask.NameToLayer("Ground"), true, Color.gray);
            RaycastHit2D raycastDownwards = CorgiTools.CorgiRayCast(transform.position, Vector2.up, RaycastLength, 1 << LayerMask.NameToLayer("Ground"), true, Color.gray);

            // if we see an obstacle, we reposition the object
            if (raycastUpwards)
            {
                Reposition(raycastUpwards.collider.transform.position);
            }
            if (raycastDownwards)
            {
                Reposition(raycastDownwards.collider.transform.position);
            }
        }
Пример #10
0
 /// <summary>
 /// Updates all mecanim animators.
 /// </summary>
 protected virtual void UpdateAllMecanimAnimators()
 {
     CorgiTools.UpdateAnimatorBool(_animator, "Grounded", IsGrounded);
     CorgiTools.UpdateAnimatorFloat(_animator, "VerticalSpeed", _rigidbodyInterface.Velocity.y);
 }
Пример #11
0
        /// <summary>
        /// On start, we make our dragon flicker
        /// </summary>
        protected virtual void Start()
        {
            Color flickerColor = new Color(1, 1, 1, 0.5f);

            StartCoroutine(CorgiTools.Flicker(GameManager.Instance.CurrentPlayableCharacters[0].GetComponent <Renderer>(), flickerColor, 0.1f, 3f));
        }