private void Update() { if (!buildMode) { return; } if (placingBuilding) { Ray ray = playerCam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; Physics.Raycast(ray, out hit, 1000, 1 << LayerMask.NameToLayer("Terrain")); if (hit.collider != null) { building.transform.position = Positioning.GetSnappedPosition(hit.point); if (buildingScript.GridSizeX == 2 && buildingScript.GridSizeY == 2) { building.transform.position -= new Vector3(0.5f, 0f, 0.5f); } } if (Input.GetMouseButtonDown(0) && placementGrid.IsPlacementValid()) { DeployBuilding(); } } else { CheckInputs(); } }
public static void FindStructureLocation() { Vector3 newLocation = RTSInterfacing.GetWorldPos3(Input.mousePosition); if (RTSInterfacing.HitPointIsGround(Input.mousePosition) && lastLocation != newLocation) { lastLocation = newLocation; tempStructure.transform.position = Positioning.GetSnappedPosition(newLocation); if (_constructingWall) { WallPositioningHelper.Visualize(); } } }
public static void CreateStructure(string buildingName, RTSAgent constructingAgent, Rect playingArea) { Vector2d buildPoint = new Vector2d(constructingAgent.transform.position.x, constructingAgent.transform.position.z + 10); RTSAgent buildingTemplate = GameResourceManager.GetAgentTemplate(buildingName); if (buildingTemplate.MyAgentType == AgentType.Building && buildingTemplate.GetComponent <Structure>()) { // check that the Player has the resources available before allowing them to create a new structure if (!_cachedCommander.CachedResourceManager.CheckResources(buildingTemplate)) { Debug.Log("Not enough resources!"); } else { tempObject = Object.Instantiate(buildingTemplate.gameObject, new Vector3(0, 0, 0), Quaternion.identity) as GameObject; if (tempObject) { _findingPlacement = true; SetTransparentMaterial(tempObject, GameResourceManager.AllowedMaterial); tempObject.gameObject.name = buildingName; tempStructure = tempObject.GetComponent <Structure>(); if (tempStructure.StructureType == StructureType.Wall) { // walls require a little help since they are click and drag _constructingWall = true; tempStructure.IsOverlay = true; WallPositioningHelper.Setup(); } tempStructureBody = tempObject.GetComponent <UnityLSBody>().InternalBody; // structure size is 2 times the size of halfwidth & halfheight tempStructure.BuildSizeLow = (tempStructureBody.HalfWidth.CeilToInt() * 2); tempStructure.BuildSizeHigh = (tempStructureBody.HalfLength.CeilToInt() * 2); cachedAgent = constructingAgent; tempStructure.gameObject.transform.position = Positioning.GetSnappedPosition(buildPoint.ToVector3()); } } } }
public static void Visualize() { _currentPos = tempWallPillarGO.transform.position; if (!_isPlacingWall) { GameObject closestPillar = ClosestPillar(_currentPos, _pillarRangeOffset); if (closestPillar.IsNotNull()) { tempWallPillarGO.transform.position = closestPillar.transform.position; tempWallPillarGO.transform.rotation = closestPillar.transform.rotation; _startSnapped = true; } else { _startSnapped = false; tempWallPillarGO.transform.position = Positioning.GetSnappedPosition(_currentPos); } } else { UpdateWall(); } }