예제 #1
0
    /// <summary>
    /// Spawns bullet holes.
    /// </summary>
    /// <param name="holeCount">Number of bullet holes to spawn.</param>
    private void SpawnBulletHoles(int holeCount)
    {
        while (m_bulletHoles.Count < holeCount)
        {
            // Randomize bullet hole position
            Vector2 holePos = new Vector2(Random.Range(m_holeSpawnAreaMin.x, m_holeSpawnAreaMax.x),
                                          Random.Range(m_holeSpawnAreaMin.y, m_holeSpawnAreaMax.y));

            // Spawn the first few bullet holes outside the instruction text area
            if (m_bulletHoles.Count < (float)holeCount * 0.5f)
            {
                // If position is within the instruction text area, re-randomize a new position
                if (holePos.x > m_textAreaMin.x && holePos.x < m_textAreaMax.x &&
                    holePos.y > m_textAreaMin.y && holePos.y < m_textAreaMax.y)
                {
                    continue;
                }
            }

            // Make sure there is enough space between holes
            bool  isSpaced  = true;
            float minDistSq = m_minDistBetweenHoles * m_minDistBetweenHoles;
            foreach (BulletHole hole in m_bulletHoles)
            {
                if ((hole.transform.position - (Vector3)holePos).sqrMagnitude < minDistSq)
                {
                    isSpaced = false;
                    break;
                }
            }
            // If not spaced enough from other holes, re-randomize a new position
            if (!isSpaced)
            {
                continue;
            }

            // Spawn a bullet hole
            BulletHole bulletHole = SpawnBulletHole(holePos);
            Vector3    bloodDir   = Vector3.Normalize((Vector3)holePos - m_bloodSource.position);
            bulletHole.Initialize(this, m_bloodDropResource, m_initialBloodDropSpeed * bloodDir,
                                  m_bloodDropGravity, UICamera.ScreenMinWorld.y - 5.0f);
            // Start bullet hole hidden
            bulletHole.Hide();
        }
    }