예제 #1
0
    // Update is called once per frame
    void Update()
    {
        //Stun hitstate
        startingNewAttack = false;
        if (stunTime > 0.0f)
        {
            if (stunTime != maxStun)
            {
                anim.SetBool("hitInit", false);
            }
            stunTime = Mathf.Max(0.0f, stunTime - Time.deltaTime);
            if (stunTime == 0.0f && attackable.alive)
            {
                endStun();
            }
        }
        else if (!attackable.alive)
        {
            startHitState(3.0f);
        }
        if (currentAttackName != "none")
        {
            currentAttack.timeSinceStart = currentAttack.timeSinceStart + Time.deltaTime;
            currentAttack.startUpTick();

            if (hitboxCreated == false)
            {
                if (startUpTime <= (Time.deltaTime / 2))
                {
                    hitboxCreated = true;
                    currentAttack.onAttack();

//					if (currentAttack.soundFX != null) {currentAttack.soundFX.Play ();}
                    if (AttackSound != null)
                    {
                        AudioSource.PlayClipAtPoint(AttackSound, gameObject.transform.position);
                    }
                    if (currentAttack.attackFX && onBeat)
                    {
                        addEffect(currentAttack.attackFX, currentAttack.recoveryTime + 0.2f);
                    }

                    if (currentAttack.createHitbox)
                    {
                        Vector2 realKB  = currentAttack.knockback;
                        Vector2 realOff = currentAttack.offset;
                        float   damage  = currentAttack.damage;
                        float   stun    = currentAttack.stun;
                        hbm.addAttrs(currentAttack.hitType);
                        if (gameObject.GetComponent <Movement> ().facingLeft)
                        {
                            realKB  = new Vector2(-currentAttack.knockback.x, currentAttack.knockback.y);
                            realOff = new Vector2(-currentAttack.offset.x, currentAttack.offset.y);
                        }
                        if (!onBeat && GetComponent <Player> ())
                        {
                            Player plyr = GetComponent <Player> ();
                            stun   *= plyr.mistimedStunRatio;
                            realKB *= plyr.mistimedKBRatio;
                            damage *= plyr.mistimedDamageRatio;
                        }
                        hbm.hitboxReflect = reflectProj;
                        hbm.stun          = stun;
                        hbm.createHitbox(currentAttack.hitboxScale, realOff, damage, currentAttack.hitboxDuration, realKB, true, myFac, true);
                    }
                    if (currentAttack.recoveryAnimID > 0)
                    {
                        anim.SetInteger("attack", currentAttack.recoveryAnimID);
                    }
                }
                else
                {
                    startUpTime = Mathf.Max(0.0f, startUpTime - Time.deltaTime);
                }
            }
            else
            {
                if (recoveryTime <= Time.deltaTime / 2.0f)
                {
                    endAttack();
                }
                else
                {
                    currentAttack.recoveryTick();
                    recoveryTime = Mathf.Max(0.0f, recoveryTime - Time.deltaTime);
                }
            }
        }
    }
예제 #2
0
    protected void update()
    {
        m_startingNewAttack = false;
        if (stunTime > 0.0f)
        {
            m_anim.Play(HurtAnimation, true);

            stunTime = Mathf.Max(0.0f, stunTime - Time.deltaTime);
            if (stunTime == 0.0f && m_attackable.alive)
            {
                endStun();
            }
        }
        else if (!m_attackable.alive)
        {
            startHitState(3.0f);
        }
        else if (CurrentAttackName != "none")
        {
            m_currentAttack.timeSinceStart = m_currentAttack.timeSinceStart + Time.deltaTime;
            m_currentAttack.startUpTick();

            if (m_hitboxCreated == false)
            {
                if (startUpTime <= (Time.deltaTime / 2))
                {
                    m_hitboxCreated = true;

                    m_currentAttack.onAttack();

                    if (m_currentAttack.attackSoundFX != null)
                    {
                        AudioSource.PlayClipAtPoint(m_currentAttack.attackSoundFX, transform.position);
                    }
                    if (AttackSound != null)
                    {
                        AudioSource.PlayClipAtPoint(AttackSound, gameObject.transform.position);
                    }
                    if (m_currentAttack.attackFX)
                    {
                        addEffect(m_currentAttack.attackFX, m_currentAttack.recoveryTime + 0.2f);
                    }

                    if (m_currentAttack.CreateHitbox)
                    {
                        Vector2 kb      = m_currentAttack.knockback;
                        Vector2 realOff = m_currentAttack.HitboxOffset;
                        float   damage  = m_currentAttack.damage;
                        float   stun    = m_currentAttack.stun;
                        m_hitboxMaker.addAttrs(m_currentAttack.hitType);
                        realOff = gameObject.GetComponent <PhysicsTD> ().OrientVectorToDirection(m_currentAttack.HitboxOffset);
                        m_hitboxMaker.createHitbox(m_currentAttack.HitboxScale, realOff, damage, stun, m_currentAttack.hitboxDuration, kb, true, m_faction, true);
                    }
                    m_anim.Play(m_currentAttack.RecoveryAnimation, true);
                }
                else
                {
                    startUpTime = Mathf.Max(0.0f, startUpTime - Time.deltaTime);
                }
            }
            else
            {
                if (recoveryTime <= Time.deltaTime / 2.0f)
                {
                    endAttack();
                }
                else
                {
                    m_currentAttack.recoveryTick();
                    recoveryTime = Mathf.Max(0.0f, recoveryTime - Time.deltaTime);
                }
            }
        }
        else
        {
            playAnimations();
        }
    }