void BlockGotClicked(Block block, MCFace face)
 {
     if (HasToolSelected())
     {
         currentTool.UseTool(block, face);
     }
 }
 public void UseTool(Block blockToUseToolOn, MCFace face)
 {
     if (coolDownRemaining <= 0)
     {
         Use(blockToUseToolOn, face);
         coolDownRemaining = coolDown;
     }
 }
Example #3
0
    private void DoHit(RaycastHit hit)
    {
        MCFace face = GetHitFace(hit);

        if (OnBlockClicked != null)
        {
            OnBlockClicked(this, face);
        }
    }
    public void showPreview(RaycastHit hit2)
    {
        if (currentObject.sort == objectsorts.floor)
        {
            dir = GetHitFace(hit2);

            if (dir == MCFace.Up || dir == MCFace.Down)
            {
                currentPos = hit2.point;
            }
            else
            {
                if (dir == MCFace.North)
                {
                    currentPos = hit2.point + new Vector3(0, 0, 2);
                }

                if (dir == MCFace.South)
                {
                    currentPos = hit2.point + new Vector3(0, 0, -2);
                }

                if (dir == MCFace.East)
                {
                    currentPos = hit2.point + new Vector3(2, 0, 0);
                }

                if (dir == MCFace.West)
                {
                    currentPos = hit2.point + new Vector3(-2, 0, 0);
                }
            }
        }
        else
        {
            currentPos = hit2.point;
        }
        currentPos -= Vector3.one * offset;
        currentPos /= gridSize;
        currentPos  = new Vector3(Mathf.Round(currentPos.x), Mathf.Round(currentPos.y), Mathf.Round(currentPos.z));
        currentPos *= gridSize;
        currentPos += Vector3.one * offset;
        currentPreview.position = currentPos;

        if (Input.GetKeyDown(KeyCode.R))
        {
            currentRot += new Vector3(0, 90, 0);
        }
        currentPreview.localEulerAngles = currentRot;
    }
Example #5
0
    protected override void Use(Block blockToUseToolOn, MCFace face)
    {
        bool    success     = true;
        Vector3 newPosition = blockToUseToolOn.transform.position;
        float   scale       = 0.3f;

        Debug.Log("Face " + face + " is available");
        switch (face)
        {
        case MCFace.Up:
            newPosition.y += scale;
            break;

        case MCFace.East:
            newPosition.x += scale;
            break;

        case MCFace.West:
            newPosition.x -= scale;
            break;

        case MCFace.North:
            newPosition.z += scale;
            break;

        case MCFace.South:
            newPosition.z -= scale;
            break;

        case MCFace.Down:
        case MCFace.None:
        default:
            Debug.Log("Won't place a block on face " + face);
            success = false;
            break;
        }

        if (success)
        {
            Debug.Log("Placing Block on " + face);
            GameObject blockGO = Instantiate(blockPrefab, newPosition, Quaternion.identity);
            //update texture if user selected a custom one.
            if (currentTexture != null)
            {
                blockGO.GetComponent <Renderer>().material.mainTexture = currentTexture;
            }
        }
    }
    public void PlaceNextCube(RaycastHit hit)
    {
        MCFace  faceClicked = GetHitFace(hit);
        Vector3 localDirNextCube;

        switch (faceClicked)
        {
        case MCFace.Down:
            localDirNextCube = Vector3.down;
            break;

        default:
            print("Incorrect intelligence level.");
            break;
        }
    }
    // private void startDestroy(){
    //     if(Physics.Raycast(cam2.position, cam2.forward, out hit3, 10))
    //     {
    //         Material originalColor = hit3.transform.gameObject.GetComponentInChildren<Renderer>().material;
    //         if(hit3.transform != this.transform && hit3.transform.gameObject.layer == 9)
    //         {
    //             print("Object hit");
    //             hit3.transform.gameObject.GetComponentInChildren<Renderer>().material = red;
    //             begone(hit3);
    //         }
    //         else
    //         {
    //             hit3.transform.gameObject.GetComponentInChildren<Renderer>().material = originalColor;
    //         }
    //     }
    // }


    // public void destroyObject()
    // {
    //     if(isDestroying)
    //     {
    //         destroy = true;
    //     }
    // }

    // private void begone(RaycastHit _hit3){
    //     if(destroy)
    //     {
    //         Destroy(_hit3.transform.gameObject);
    //         destroy = false;
    //     }
    // }

//Shows the object you want to build and it moves in a grid
    public void showPreview(RaycastHit hit2)
    {
        if (curObj.sort == objectsorts.trap || curObj.sort == objectsorts.wall || curObj.sort == objectsorts.tower)
        {
            dir = GetHitFace(hit2);
            if (dir == MCFace.Up || dir == MCFace.Down)
            {
                curPos = hit2.point;
            }
            else
            {
                if (dir == MCFace.North)
                {
                    curPos = hit2.point + new Vector3(0, 0, 2);
                }
                if (dir == MCFace.South)
                {
                    curPos = hit2.point + new Vector3(0, 0, -2);
                }
                if (dir == MCFace.East)
                {
                    curPos = hit2.point + new Vector3(2, 0, 0);
                }
                if (dir == MCFace.West)
                {
                    curPos = hit2.point + new Vector3(-2, 0, 0);
                }
            }
        }
        else
        {
            curPos = hit2.point;
        }
        curPos          -= Vector3.one * offset;
        curPos          /= gridSize;
        curPos           = new Vector3(Mathf.Round(curPos.x), Mathf.Round(curPos.y), Mathf.Round(curPos.z));
        curPos          *= gridSize;
        curPos          += Vector3.one * offset;
        curPrev.position = curPos;
        //Turns the object around by pressing the left mouse button
        if (Input.GetButtonDown("Fire2"))
        {
            curRot += new Vector3(0, 90, 0);
            curPrev.localEulerAngles = curRot;
        }
    }
 protected override void Use(Block blockToUseToolOn, MCFace face)
 {
     Destroy(blockToUseToolOn.gameObject);
     Debug.Log("detroyed a block");
 }
 protected abstract void Use(Block blockToUseToolOn, MCFace face);
Example #10
0
 protected override void Use(Block blockToUseToolOn, MCFace face)
 {
     blockToUseToolOn.UpdateTextureTo(texture);
     Debug.Log("adjusted texture from block");
 }
Example #11
0
    public void ShowPreview(RaycastHit hit2)
    {
        if (currObject.sort == ObjectSorts.floor)
        {
            direction = GetHitFace(hit2);
            if (direction == MCFace.Up || direction == MCFace.Down)
            {
                currPosition = hit2.point;
            }
            else
            {
                if (direction == MCFace.North)
                {
                    currPosition = hit2.point + northOffset;
                }
                if (direction == MCFace.South)
                {
                    currPosition = hit2.point + southOffset;
                }
                if (direction == MCFace.East)
                {
                    currPosition = hit2.point + eastOffset;
                }
                if (direction == MCFace.West)
                {
                    currPosition = hit2.point + westOffset;
                }
            }
        }
        else
        {
            currPosition = hit2.point;
        }

        if (hit2.transform.gameObject.CompareTag("Pillar"))
        {
            if (hit2.transform.position.x < cam.position.x)
            {
                currPosition.x += 2.0f;
            }
            else if (hit2.transform.position.x > cam.position.x)
            {
                currPosition.x -= 2.0f;
            }

            if (hit2.transform.position.z < cam.position.z)
            {
                currPosition.z += 2.0f;
            }
            else if (hit2.transform.position.z > cam.position.z)
            {
                currPosition.z -= 2.0f;
            }
        }

        currPosition    -= Vector3.one * offset;
        currPosition    /= gridSize;
        currPosition     = new Vector3(Mathf.Round(currPosition.x), Mathf.Round(currPosition.y), Mathf.Round(currPosition.z));
        currPosition    *= gridSize;
        currPosition    += Vector3.one * offset;
        preview.position = currPosition;

        if (Input.GetMouseButtonDown(1))
        {
            angle        = (angle + 90.0f) % 360.0f;
            currRotation = new Vector3(0.0f, angle, 0.0f);
        }

        preview.localEulerAngles = currRotation;
    }