Exemplo n.º 1
0
    void showBlock()
    {
        Vector3    pos = this.camera.transform.position;
        Vector3    dir = this.camera.transform.forward;
        Quaternion rot = this.camera.transform.rotation;

        rot.y = 90;

        Vector3 spawnPos = pos + dir * this.blockDist;

        this.tmpBlock     = Instantiate(this.goldBrick, spawnPos, rot) as GameObject;
        this.tmpBlock.tag = "buildBlock";

        this.tmpShadow = Instantiate(this.shadow, spawnPos, this.shadow.transform.rotation) as GameObject;
        this.tmpShadow.transform.parent = this.tmpBlock.transform;

        this.tmpBlock.AddComponent("PlaceBlockDetection");
        PlaceBlockDetection spt = (PlaceBlockDetection)this.tmpBlock.GetComponent("PlaceBlockDetection");

        spt.detectionColor             = new Color(0.5f, 0, 0, 0.5f);
        this.tmpBlock.transform.parent = this.camera.transform;                                                                          //this.transform;

        this.tmpBlock.transform.rotation = Quaternion.Euler(this.lockPos, this.tmpBlock.transform.rotation.eulerAngles.y, this.lockPos); //In order to stop the block from rotating around to the camera rotation we need to reset the rotation back after we init the block
        Color col = this.tmpBlock.renderer.material.color;

        col.a = 0.5f;
        this.tmpBlock.renderer.material.color = col;
    }
Exemplo n.º 2
0
    void placeBlock()
    {
        //Before we can place a block we need to make sure it isnt inside another object
        PlaceBlockDetection spt = (PlaceBlockDetection)this.tmpBlock.GetComponent("PlaceBlockDetection");

        if (this.tmpBlock.transform.position.y < 0 || spt.IsInideObject() == true)        //Destroy the block
        {
            Vector3 tmpPos = this.tmpBlock.transform.position;
            tmpPos.y = -1000;
            this.tmpBlock.transform.position = tmpPos;

            Destroy(this.tmpBlock, 0.1f);
            tmpBlock = null;
        }
        else
        {
            this.tmpBlock.transform.parent   = this.Building.transform;
            this.tmpBlock.collider.isTrigger = false;                   //Because we have place the block onto the game scene we no longer want it to just be a trigger
            this.tmpBlock.collider.attachedRigidbody.useGravity = true; //Allow gravity to affect the block
            Color col = this.tmpBlock.renderer.material.color;
            col.a = 1;
            this.tmpBlock.renderer.material.color = col;

            spt.detectionColor = new Color(0.5f, 0.5f, 0);
            spt.col            = col;

            this.tmpBlock.constantForce.enabled = true;
            this.tmpBlock.tag = "Gold";

            this.tmpBlock = null;
            this.player.removeBlock();

            AudioSource source = this.audioSource.GetComponent <AudioSource> ();

            source.PlayOneShot(this.dropGold, 1f);
        }

        this.blockDist = this.initBlockDist;
    }