コード例 #1
0
ファイル: APSampleBlob.cs プロジェクト: chiring/mechanimlb
    // called when character motor ray is touching us
    override public void OnCharacterTouch(APCharacterController character, APCharacterMotor.RayType rayType)
    {
        // Do nothing if dead
        if (IsDead())
        {
            return;
        }

        // prevent checking hits too often
        if (Time.time < m_lastHitTime + m_minTimeBetweenTwoReceivedHits)
        {
            return;
        }

        // save current hit time
        m_lastHitTime = Time.time;

        // check if jumping on us
        APSamplePlayer samplePlayer = character.GetComponent <APSamplePlayer>();

        if (rayType == APCharacterMotor.RayType.Ground)
        {
            // make character jump
            float  fRatio      = m_jumpRatioInputReleased;
            string sJumpButton = character.m_jump.m_button;
            if (!string.IsNullOrEmpty(sJumpButton) && Input.GetButton(sJumpButton))
            {
                fRatio = m_jumpRatioInputPushed;
            }

            if (fRatio > 0f)
            {
                character.Jump(fRatio);
            }

            // add hit to us
            AddHitDamage(samplePlayer.m_jumpDamage);
        }
        else
        {
            // notify hit to character controller as Blob makes damage by touching it
            samplePlayer.OnHit(this);
        }
    }
コード例 #2
0
    // called when character is entering this collectable
    public void OnTriggerEnter2D(Collider2D otherCollider)
    {
        APSamplePlayer character = otherCollider.GetComponent <APSamplePlayer>();

        if (character && !character.IsGodModeEnabled())
        {
            // prevent checking hits too often
            if (Time.time < m_lastHitTime + m_minTimeBetweenTwoReceivedHits)
            {
                return;
            }

            // save current hit time
            m_lastHitTime = Time.time;

            // add hit to character
            character.OnHit(m_touchDamage, transform.position);
        }
    }
コード例 #3
0
    // called when character motor ray is touching us
    override public bool OnCharacterTouch(APCharacterController character, APCharacterMotor.RayType rayType, RaycastHit2D hit, float penetration,
                                          APMaterial hitMaterial)
    {
        // Do nothing if dead
        if (IsDead())
        {
            return(false);
        }

        // Do nothing in godmode
        APSamplePlayer samplePlayer = character.GetComponent <APSamplePlayer>();

        if (samplePlayer && samplePlayer.IsGodModeEnabled())
        {
            return(false);
        }

        // check if jumping on us
        bool bHit = false;

        if ((rayType == APCharacterMotor.RayType.Ground) && (penetration <= m_jumpHitPenetrationTolerance))
        {
            // make character jump
            float fRatio = m_jumpRatioInputReleased;
            if (character.m_jump.m_button.IsSpecified() && character.m_jump.m_button.GetButton())
            {
                fRatio = m_jumpRatioInputPushed;
            }

            if (fRatio > 0f)
            {
                character.Jump(character.m_jump.m_minHeight * fRatio, character.m_jump.m_maxHeight * fRatio);
            }

            // add hit to NPC
            if (samplePlayer)
            {
                AddHitDamage(samplePlayer.m_jumpDamage);
            }

            bHit = true;
        }
        else if (penetration <= m_hitPenetrationTolerance)
        {
            // add hit to character
            if (samplePlayer)
            {
                samplePlayer.OnHit(m_touchDamage, transform.position);
            }

            bHit = true;
        }

        // prevent checking hits too often
        if (bHit)
        {
            if (Time.time < m_lastHitTime + m_minTimeBetweenTwoReceivedHits)
            {
                return(false);
            }

            // save current hit time
            m_lastHitTime = Time.time;
        }

        // always ignore contact
        return(false);
    }