コード例 #1
0
ファイル: Hud.cs プロジェクト: bmjoy/unity-minecraft
        void Awake()
        {
            interactionBarSize = interactionBar.sizeDelta;
            interactionBar.gameObject.SetActive(false);
            destroyer = player.GetComponent <BlockDestroyer>();

            inventory = GetComponentInChildren <Inventory>();
            inventory.SetBlockBuilder(player.GetComponent <BlockBuilder>());
        }
コード例 #2
0
ファイル: Block.cs プロジェクト: th1209/Breakout
    /// <summary>
    /// データ保持クラスの情報を元に、このクラスを初期化する。
    /// </summary>
    /// <param name="dataHolder">Data holder.</param>
    public void InitFromDataHolder(BlockDataHolder dataHolder)
    {
        this.breakCount = dataHolder.breakCount;
        this.hitScore   = dataHolder.hitScore;
        this.hitCount   = 0;

        this.gameObject.transform.localScale = new Vector3(dataHolder.width, 1, dataHolder.height);

        this.controller = GameObject.Find("MainController").GetComponent <MainController>();
        this.destroyer  = GameObject.Find("BlockDestroyer").GetComponent <BlockDestroyer>();

        //this.GetComponent<Renderer>().material = materialPrefabs [breakCount - 1];
    }
コード例 #3
0
    private void spawnRandomColorBlock()
    {
        int index = Random.Range(0, 3);

        if (sameColorIndex != index)
        {
            sameColorIndex = index;
            sameColorCount = 0;
        }
        if (sameColorCount >= 3)
        {
            while (index == sameColorIndex)
            {
                index = Random.Range(0, 3);
            }
            sameColorIndex = index;
            sameColorCount = 0;
        }
        sameColorCount++;
        sameColorIndex = index;
        GameObject block = Instantiate(blockPrefab, spawnPosition.position, Quaternion.identity) as GameObject;

        block.GetComponent <Rigidbody2D>().angularVelocity = blockRotation;

        BlockDestroyer blockObj = block.GetComponent <BlockDestroyer>();

        switch (index)
        {
        case 0:
            block.tag = firstColorName;
            blockObj.setColor(firstColor);
            break;

        case 1:
            block.tag = secondColorName;
            blockObj.setColor(secondColor);
            break;

        case 2:
            block.tag = thirdColorName;
            blockObj.setColor(thirdColor);
            break;
        }
    }