Beispiel #1
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0) && isBuilding && previewScript.CanBuild()) //pressing LMB, and isBuiding = true, and the Preview Script -> canBuild = true
        {
            BuildIt();                                                             //then build the thing
        }

        if (Input.GetMouseButtonDown(1) && isBuilding)//stop build
        {
            // StopBuild();
        }

        if (Input.GetKeyDown(KeyCode.R) && isBuilding) //for rotation
        {
            preview.transform.Rotate(0f, 90f, 0f);     //spins like a top, in 90 degree turns
        }

        if (isBuilding)
        {
            DoRay();
        }
        else
        {
            RayDrag();
        }
    }
Beispiel #2
0
    private void Update()
    {
        int mask = 1 << LayerMask.NameToLayer("FurniturePrefabs");

        if (!IsPointerOverUIObject(Input.mousePosition))
        {
            if (selector.isBuildStart == false)
            {
                return;
            }

            if (Input.GetMouseButtonDown(0) && isBuilding && previewScript.CanBuild())//pressing LMB, and isBuiding = true, and the Preview Script -> canBuild = true
            {
                //BuildIt();//then build the thing
            }

            else if (Input.GetMouseButtonDown(1) && isBuilding)//stop build
            {
                previewScript.GetComponent <PreviewObj>().SetOriginalColor();
                StopBuild();
            }

            else if (Input.GetMouseButtonDown(0))
            {
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                Physics.Raycast(ray, out hit, 9999f, mask);

                if (!isBuilding)
                {
                    if (hit.collider.CompareTag("Furniture") && Relocation)
                    {
                        selector.furnitureId = int.Parse(hit.collider.name.Substring(0, 3));
                        Destroy(hit.collider.gameObject);
                        isBuilding = true;
                        GameObject go = null;
                        foreach (var item in furniturePreviewPrefabs)
                        {
                            if (item.name.Contains(selector.furnitureId.ToString()))
                            {
                                go = item;
                            }
                        }
                        if (go != null)
                        {
                            NewBuild(go);
                        }
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.R) && isBuilding) //for rotation
        {
            preview.transform.Rotate(0f, 90f, 0f);     //spins like a top, in 90 degree turns
        }

        if (isBuilding)
        {
            DoRay();
        }
    }