Exemple #1
0
    private void MouseClick()
    {
        if (Input.GetMouseButtonUp(0))
        {
            build = false;
            return;
        }

        if (!Input.GetMouseButton(0) && !Input.GetMouseButtonUp(0))
        {
            return;
        }

        Vector2      position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        RaycastHit2D hit      = Physics2D.Raycast(position, Vector2.zero, layerMask);

        if (!build && hit.collider != null && hit.collider.gameObject.layer == 9 && Input.GetMouseButtonUp(0))
        {
            builderScript.CmdBuild(buildingPlacement.transform.position, builderScript.selectedBuilding);
            build = true;
            SetSelectedBuilding(playerBuilder.GetSelectedBuilding().Gameobject);
        }
        else if (hit.collider == null && Input.GetMouseButton(0) && buildingPlacement.activeSelf)
        {
            builderScript.CmdBuild(buildingPlacement.transform.position, builderScript.selectedBuilding);
            build = true;
            SetSelectedBuilding(null);
        }
        else if (hit.collider == null || hit.collider.gameObject.layer != 9)
        {
            SetSelectedBuilding(null);
        }
        else
        {
            SetSelectedBuilding(builderScript.GetBuilding(selectedBuilding));
        }
    }