private void CreateBuilding() { var position = grid.GetGridPostion(CameraUtils.GetMousePosition3D()); if (!grid.IsInsideGrid(position.X, position.Y)) { DebugPopup.Create("Can't create here."); return; } var gridObject = new GridObject( CurrentBuilding.Width, CurrentBuilding.Height, currentDirection ); if (!grid.TrySetGridValue(grid.GetWorldPosition(position.X, position.Y), gridObject)) { return; } var building = buildingPooling.GetAvailableObject(CurrentBuilding.Tag).Get(); building .GetComponent <Building>() .Setup(gridObject) .Activate((go) => { go .transform .position = grid.GetWorldPosition(position.X, position.Y, gridObject); go .transform .rotation = Quaternion.Euler(0f, currentDirection.Rotation, 0f); }); }
private void Update() { if (ghostTransform == null) { return; } var canBuild = BuildingPlacementSystem .Instance .CanBuild( CameraUtils.GetMousePosition3D(), out Vector3 buildingPosition, out Quaternion buildingRotation ); if (canBuild) { ghostTransform.gameObject.SetActive(true); transform.position = buildingPosition; transform.rotation = buildingRotation; } else { ghostTransform.gameObject.SetActive(false); } }
public static void Create(string text) { var gameObject = new GameObject( "debug_popup", typeof(TextMeshPro), typeof(SimplePopup) ); var transform = gameObject.GetComponent <RectTransform>(); var mousePosition = CameraUtils.GetMousePosition3D(); transform.rotation = Camera.main.transform.rotation; transform.localPosition = mousePosition + new Vector3(0f, 0.1f, 0f); var textMesh = gameObject.GetComponent <TextMeshPro>(); textMesh.text = text; textMesh.color = Color.white; textMesh.fontSize = 2; textMesh.alignment = TextAlignmentOptions.Midline; Object.Destroy(gameObject, 5f); }