Пример #1
0
    /// <summary>
    /// Spawns a coin object.
    /// </summary>
    /// <returns>The coin handler instance</returns>
    private CoinUIObject SpawnCoin()
    {
        GameObject   coinObj = GameObject.Instantiate <GameObject>(m_coinPrefab);
        CoinUIObject coin    = coinObj.AddComponentNoDupe <CoinUIObject>();

        m_coins.Add(coin);
        return(coin);
    }
Пример #2
0
    /// <summary>
    /// Notifies that a coin has been collected ("collect" animation finished).
    /// </summary>
    /// <param name="coin">The coin.</param>
    public void NotifyCoinCollected(CoinUIObject coin)
    {
        // Remove the coin from the list and delete it
        m_coins.Remove(coin);
        coin.Delete();

        // If all coins have been collected, end the animation
        if (m_coins.Count == 0)
        {
            m_state = CoinAnimState.IDLE;
        }
    }
Пример #3
0
    /// <summary>
    /// Starts the actual "win coins" animation.
    /// </summary>
    private void SpawnCoins()
    {
        UICamera uiCam = Locator.GetUIManager().UICamera;
        // Spawn coins from the top edge of the screen
        float leftEdge   = uiCam.TopLeftWorld.x;
        float rightEdge  = uiCam.TopRightWorld.x;
        float bottomEdge = uiCam.ScreenMinWorld.y;
        // Add an offset to the top edge to spawn coins outside screen view
        float spawnPosY = uiCam.ScreenMaxWorld.y + m_spawnOffsetFromTopEdge;
        // Max speed of coins depends on screen orientation
        float maxSpeed = uiCam.IsLandscape ? m_maxSpeed_landscape : m_maxSpeed_portrait;

#if UNITY_EDITOR
        // Screen orientation does not apply to the Editor, so just use max speed for landscape
        maxSpeed = m_maxSpeed_landscape;
#endif
        // Spawn a number of coins equal to the specified coin amount
        //  (assuming 1 coin object = 1 coin value)
        for (int coinNo = 0; coinNo < m_coinAmount; ++coinNo)
        {
            // Randomize start position from top edge of screen
            float   spawnPosX = Random.Range(leftEdge, rightEdge);
            Vector3 spawnPos  = new Vector3(spawnPosX, spawnPosY, COIN_POS_Z);

            // Limit the angle of movement from spawn to target position
            float targetPosMinX = Mathf.Max(leftEdge, spawnPosX - m_maxTargetPosOffset);
            float targetPosMaxX = Mathf.Min(rightEdge, spawnPosX + m_maxTargetPosOffset);
            // Randomize move direction, generally downward toward the bottom screen edge
            float   targetPosX = Random.Range(targetPosMinX, targetPosMaxX);
            Vector3 targetPos  = new Vector3(targetPosX, bottomEdge, COIN_POS_Z);
            Vector3 moveDir    = Vector3.Normalize(targetPos - spawnPos);

            // Randomize initial move and rotation speeds
            float speed    = Random.Range(m_minSpeed, maxSpeed);
            float rotSpeed = Random.Range(m_minRotSpeed, m_maxRotSpeed);

            // Spawn and initialize coin object
            CoinUIObject coin = SpawnCoin();
            coin.transform.position = spawnPos;
            coin.transform.parent   = this.transform;
            coin.Initialize(this, speed, rotSpeed, moveDir, m_deceleration);
        }

        // Play win coins sound
        Locator.GetSoundManager().PlayOneShot(SoundInfo.SFXID.WinCoins);
    }