Beispiel #1
0
        public void takeDamage(Attack attack, Vector3 location)
        {
            if (holdShield)
            {   // Damage is applied on the shield
                shield.takeDamage(attack);
            }
            else
            {   // Damage is applied on the player
                //StartCoroutine("lagForSeconds", 1f);

                // generate hit effect

                Instantiate(hitEffect, findMidpoint(location, transform.position), new Quaternion(0, 0, 0, 0));
                soundEffect.playSound(1);
                Vector2 finalKnockback = health.takeDamage(attack);

                hurtLagTime = computeLagTime(attack.hasUniformKnockback);
                //StartCoroutine("hurtLag", hurtLagTime);

                hasControl = false;
                anime.setAnimator(AnimeState.IsHurt);
                isHurt      = true;
                rb.velocity = finalKnockback;
                //UnityEngine.Debug.Log(rb.velocity.x);

                if (finalKnockback.y < -4f)
                {
                    stageBounce = new StageBounce(true, finalKnockback.y * -0.25f);
                }
            }
        }
Beispiel #2
0
        // Unity basic functions

        // Start is called before the first frame update
        protected void Start()
        {
            rb         = GetComponent <Rigidbody2D>();
            localScale = transform.localScale;
            //shieldObject = this.transform.Find("Shield").gameObject;
            shieldObject.SetActive(true);
            shield         = shieldObject.GetComponent <Shield>();
            anime          = GetComponent <PlayerAnime>();
            collided       = new List <string>();
            hurtboxName    = transform.GetChild(2).name; // Hurtbox should be the 3rd on the player object's list
            spriteRenderer = gameObject.GetComponent <SpriteRenderer>();
            hurtboxObject  = gameObject.transform.GetChild(2).gameObject;

            // linking button inputs to player number
            AxisHorizontal = "Horizontal" + playerNumber;
            AxisVertical   = "Vertical" + playerNumber;
            ButtonA        = "A" + playerNumber;
            ButtonB        = "B" + playerNumber;
            ButtonJump     = "Jump" + playerNumber;
            ButtonFall     = "Fall" + playerNumber;
            ButtonShield   = "Shield" + playerNumber;

            stageBounce = new StageBounce(false, 0f);
        }