Esempio n. 1
0
    /// <summary>
    /// This function creates one random item from the itemlist at a random position.
    /// Y position is set according to the game direction
    /// </summary>
    /// <param name="iDirection"></param>
    public void CreateRandomItemAtRandomPosition()
    {
        Vector3 tSpawnPos        = Vector3.Lerp(_leftBound.transform.position, _rightBound.transform.position, Random.Range(0f, 1f));
        int     tRandomItemindex = Random.Range(0, itemsTierOne.Count);

        tSpawnPos.z = 0;
        switch (_gameData.direction)
        {
        case Direction.UP:
            tSpawnPos.y = _topSpawnY;
            break;

        case Direction.DOWN:
            tSpawnPos.y = _botSpawnY;
            break;
        }
        GameObject tItem;

        if (itemParent.transform.position.y < 333f)
        {
            tItem = Instantiate(itemsTierOne[tRandomItemindex], tSpawnPos, Quaternion.identity, itemParent);
        }
        else if (itemParent.transform.position.y < 666f)
        {
            tItem = Instantiate(itemsTierTwo[tRandomItemindex], tSpawnPos, Quaternion.identity, itemParent);
        }
        else
        {
            tItem = Instantiate(itemsTierThree[tRandomItemindex], tSpawnPos, Quaternion.identity, itemParent);
        }
        ItemBase tItemScript = tItem.GetComponent <ItemBase>();

        tItemScript.itemIndexForSpawning = tRandomItemindex;
        _itemController.AddItemToList(tItem.GetComponent <ItemBase>());
    }