Example #1
0
    //спавн крана
    private void SpawnCrane()
    {
        int           cellToDrop     = Random.Range(1, GameFieldScript.instance.width + 1);
        int           boxPrefabIndex = Random.Range(0, boxPrefabs.Length);
        MoveDirection craneMoveDir   = (MoveDirection)Random.Range(0, 2);
        CraneScript   crane;

        //создание крана двигающегося в нужном напрвалении
        if (craneMoveDir == MoveDirection.Left)
        {
            crane                     = ((GameObject)Instantiate(cranePrefab, rightCraneCell.transform.position, Quaternion.identity)).GetComponent <CraneScript>();
            crane.currCell            = rightCraneCell;
            rightCraneCell.cellObject = crane;
        }
        else
        {
            crane                    = ((GameObject)Instantiate(cranePrefab, leftCraneCell.transform.position, Quaternion.identity)).GetComponent <CraneScript>();
            crane.currCell           = leftCraneCell;
            leftCraneCell.cellObject = crane;
        }
        crane.moveDirection       = craneMoveDir;
        crane.transform.position += crane.offset;
        crane.transform.SetParent(sceneRoot);
        crane.cellCount = cellToDrop;

        //создание нужного ящика
        BoxScript box = ((GameObject)Instantiate(boxPrefabs[boxPrefabIndex], Vector3.zero, Quaternion.identity)).GetComponent <BoxScript>();

        box.transform.SetParent(crane.transform);
        box.transform.position = crane.currCell.transform.position + box.offset;
        crane.box = box;
        box.bonus = SpawnBonus();
        if (box.bonus != null)
        {
            box.InitBonusGraphic();
        }
    }