Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        m_lastUpdateTime += Time.deltaTime;
        float updateTime = 1 / m_faceUpdateSpeed;

        if (m_lastUpdateTime > updateTime)
        {
            m_lastUpdateTime = 0;
            m_index++;

            if (m_index > 100000000)
            {
                m_index = 0;
            }

            float healthPercentage = (float)m_health.GetCurrentHealth() / m_health.GetMaxHealth();
            if (healthPercentage > 0.75f || m_endGame.IsGameFinished())
            {
                m_renderer.sprite = m_happyFaces[m_index % m_happyFaces.Count];
            }
            else if (healthPercentage > 0.35f)
            {
                m_renderer.sprite = m_midFaces[m_index % m_midFaces.Count];
            }
            else
            {
                m_renderer.sprite = m_sadFaces[m_index % m_sadFaces.Count];
            }
        }
    }
Exemple #2
0
    public bool Active()
    {
        AIDamage damage = GetComponent <AIDamage>();

        if (damage != null && damage.IsDead())
        {
            return(false);
        }

        PlayerHealth playerHealth = GameMaster.GetPlayer()?.GetComponent <PlayerHealth>();

        if (playerHealth != null && playerHealth.IsDead())
        {
            return(false);
        }

        PlayerEndGame playerEndGame = GameMaster.GetPlayer()?.GetComponent <PlayerEndGame>();

        if (playerEndGame != null && playerEndGame.IsGameFinished())
        {
            return(false);
        }

        return(m_triggerArea == null || m_triggerArea.Active());
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (m_endGame.IsGameFinished() || m_health.IsDead())
        {
            return;
        }

        if (m_currentAttackSpeed > 0)
        {
            m_attackCooldown += Time.deltaTime;
            if (m_controls.AttackPressed())
            {
                float attackRate = (1 / m_currentAttackSpeed);
                if (m_attackCooldown > attackRate)
                {
                    Attack();
                    m_attackCooldown = 0.0f;
                }
            }
        }
    }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        if (m_endGame.IsGameFinished() || m_health.IsDead())
        {
            return;
        }

        Vector2 movementDirection = DesiredMovementDirection();

        if (movementDirection != Vector2.zero)
        {
            m_lastMovementDirection = movementDirection;

            m_rigidBody.AddForce(movementDirection * m_accelerationRate * m_currentMovementSpeed * Time.deltaTime);

            if (m_rigidBody.velocity.magnitude > m_currentMovementSpeed)
            {
                Vector2 velocity = m_rigidBody.velocity;
                velocity.Normalize();
                m_rigidBody.velocity = velocity * m_currentMovementSpeed;
            }
        }
    }