Пример #1
0
    /*
     * Brief: determines and displays player phase level and determines whether the player should be forced to swap each frame
     */
    void Update()
    {
        // get the player's current phase state
        m_playerPhased = m_playerSwap.m_isPhased;

        // if the player is phased and the phase level hasn't reached its minimum, decrease the phase level
        if (m_playerPhased && m_phaseLevel > 0.0f)
        {
            m_phaseLevel -= m_rate * Time.deltaTime;
        }
        // if the player is not phased and the phase level hasn't reached its maximum, increase the phase level
        else if (!m_playerPhased && m_phaseLevel < m_maxPhase)
        {
            m_phaseLevel += m_rate * Time.deltaTime;
        }

        // if the player is phased and the phase level is depleted, or if the player is not phased and the phase level has maxed out, force the player to swap states
        if (m_phaseLevel <= 0.0f && m_playerPhased || m_phaseLevel >= m_maxPhase && !m_playerPhased)
        {
            m_playerSwap.m_isPhasing = true;
            m_playerSwap.m_isPhased  = !m_playerSwap.m_isPhased;

            // edit the alpha of the enemies
            m_enemyMaterialEditor.EditEnemyAlpha(m_playerSwap.m_isPhased);
        }

        // determine the y scale of the bar using the phase level
        gameObject.GetComponent <RectTransform>().localScale = new Vector3(m_scale.x, (m_phaseLevel / m_maxPhase) * m_scale.y, m_scale.z);
    }
    /*
     * Brief: gets the player's shader
     */
    void Start()
    {
        m_shader = gameObject.GetComponent <Renderer>().materials[1];

        // store the enemy material editor
        m_enemyMaterialEditor = m_enemyMaterialManager.GetComponent <EnemyMatEdit>();
        m_enemyMaterialEditor.EditEnemyAlpha(m_isPhased);
    }
Пример #3
0
    /*
     * Brief: Initialisation for the swap bar
     */
    void Start()
    {
        // store player's swap script and scale of the bar
        m_playerSwap = GameObject.FindGameObjectWithTag("Swap").GetComponent <PlayerSwap>();
        m_scale      = gameObject.GetComponent <RectTransform>().localScale;

        // store the enemy material editor
        m_enemyMaterialEditor = m_enemyMaterialManager.GetComponent <EnemyMatEdit>();
        m_enemyMaterialEditor.EditEnemyAlpha(m_playerSwap.m_isPhased);
    }
    /*
     * Brief: manage the swapping of the player
     */
    void Update()
    {
        // if the swap button is pressed, start phasing
        if ((Input.GetButtonDown("Swap") || XCI.GetButtonDown(XboxButton.X)) && !m_isPhasing)
        {
            // set m_isPhasing to true so the phase animation begins
            m_isPhasing = true;
            // swap the current phase state of the player
            m_isPhased = !m_isPhased;

            // edit the alpha of the enemy
            m_enemyMaterialEditor.EditEnemyAlpha(m_isPhased);
        }

        // if the player is phasing, update the shader
        if (m_isPhasing)
        {
            // increase the timer
            m_phaseTimer += Time.deltaTime;

            // if the player is phased
            if (m_isPhased)
            {
                // increase the value of the shader
                m_shader.SetFloat("_Cloak_per", m_phaseTimer);
            }
            // if the player is not phased
            else
            {
                // decrease the value of the shader
                m_shader.SetFloat("_Cloak_per", 1.0f - m_phaseTimer);
            }

            // if the phase timer has run out, stop phasing
            if (m_phaseTimer >= m_timeTillPhased)
            {
                // stop phasing
                m_isPhasing = false;
                // set value of shader to intended value
                m_shader.SetFloat("_Cloak_per", (m_isPhased) ? 1 : 0);
                // reset the timer
                m_phaseTimer = 0.0f;
            }
        }
    }