Example #1
0
    void OnDamaged(float d)
    {
        Health health = GetComponent <Health>();

        if (health.IsAlive())
        {
            // set the animation control variables
            // is hurt also disables player input (hack)
            isHurt = true;
            animator.SetTrigger(hurtTriggerID);
            animator.SetBool(isHurtID, true);

            // dictate how hurt I am;
            hurtTimer.Start(hurtTimeSeconds);

            health.PushInvulnerable();
            invulnerableTimer.Start(invulnerableTimeSeconds);
            BlinkVisibility.OnObject(visual.gameObject, invulnerableTimeSeconds, .15f);

            // on hit - knock the player the oppsoite direction to what they're facing;
            float   launchDir = -GetFacing();
            float   vel_y     = MathUtil.GetVelocityToReachHeight(knockbackLift, Physics2D.gravity.y);
            Vector2 launchVel = new Vector2(launchDir * knockbackSpeed, vel_y);
            Launch(launchVel);
            ForceVelocity(launchVel.x);
        }
    }
    public static void OnObject(GameObject go, float duration, float blinkTime)
    {
        Renderer r = go.GetComponent <Renderer>();

        if (r != null)
        {
            BlinkVisibility blink = go.GetOrCreateComponent <BlinkVisibility>();
            blink.SetOptions(duration, blinkTime);
        }
    }