Пример #1
0
        public void Build(BuildingPlaceable building, Tile tile, Transform planetTransform)
        {
            tile.Content = Instantiate(building.prefab, planetTransform);

            // position
            tile.Content.transform.Translate(tile.Position, Space.Self);
            // rotation
            tile.Content.transform.rotation = Quaternion.LookRotation(tile.Position);
            tile.Content.transform.Rotate(new Vector3(90, 0, 0), Space.Self);

            Score.AddScore(-building.cost);
            ResourceWarehouse.UpdateResources(planetTransform.gameObject, (ushort)building.resourceType, 1);
        }
Пример #2
0
    private void Update()
    {
        RaycastHit hit;
        Ray        cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (current != null && canPlace() && !placed)
        {
            if (Physics.Raycast(cameraRay, out hit))
            {
                if (hit.collider.tag == "Ground")
                {
                    current.transform.position = hit.point;
                }
            }
            if (Input.GetMouseButtonDown(0) && canPlace())
            {
                current.transform.parent = null;
                placed = true;
            }
        }
        else
        {
            if (Input.GetMouseButtonDown(0) && canPlace() && !EventSystem.current.IsPointerOverGameObject())
            {
                if (Physics.Raycast(cameraRay, out hit, Mathf.Infinity, buildings, QueryTriggerInteraction.Collide))
                {
                    BuildingPlaceable buildingPlaceable = hit.collider.gameObject.GetComponent <BuildingPlaceable>();
                    if (buildingPlaceable != null)
                    {
                        buildingPlaceable.SetSelected(true);
                        placeOld = buildingPlaceable;
                    }
                }
                else
                {
                    placeOld.SetSelected(false);
                }
            }
        }
    }
Пример #3
0
 public void SetItem(GameObject b)
 {
     placed  = false;
     current = b;
     place   = current.GetComponent <BuildingPlaceable>();
 }