private void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit touchBox; Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out touchBox); if (!NeedsMoving && BuildingClickedProduction != null && IsProductionOverlayActive && CurrentOverlay.GetComponentsInChildren <ProductionScript>().All(x => x.collider != touchBox.collider)) { InitiateMoving(true); } } PositionOverlay(); }
/// <summary> /// This method is executed when an clicked on building event is fired. /// </summary> /// <param Name="evt"></param> private void OnBuildingClick(OnBuildingClick evt) { if (evt.building != null) { if (!IsProductionOverlayActive && evt.building.BuildingGame.CanProduce) { BuildingClickedProduction = evt.building; CurrentOverlay = CreatorFactoryProductionOverlay.CreateProductionOverlay(BuildingClickedProduction.type); CurrentOverlay.transform.position = GetBelowScreenPosition(); CurrentOverlay.transform.parent = Camera.main.transform; CurrentOverlay.GetComponentsInChildren <ProductionScript>().ToList().ForEach(x => x.ParentProduction = this); InitiateMoving(false); IsProductionOverlayActive = true; } } }
/// <summary> /// Move the overlay from the bottom of the screen to just above. /// </summary> public void PositionOverlay() { if (NeedsMoving) { float time = GetTimePassed(); CurrentOverlay.transform.position = Vector2.Lerp(startPosition, targetPosition, time); if (time >= 1f) { if (EndOfMovingDestroyed) { DestroyAndStopOverlay(); } else { NeedsMoving = false; CurrentOverlay.GetComponentsInChildren <ProductionScript>() .ToList().ForEach(x => x.CanClick = true); } } } }