private void HandleVortexInput() { // upon pressing the left-click button if (Input.GetButtonDown("Fire1") && canSpawnVortex) { // enable the visual indicator vortexIndicator.enabled = true; // start building the vortex scale isBuildingVortex = true; } // while holding the left-click button if (Input.GetButton("Fire1") && canSpawnVortex && isBuildingVortex) { // build up the power of the vortex over time vortexScaleProgress = Mathf.Clamp(vortexScaleProgress + Time.deltaTime, 0, vortexBuildTime); // get the current mouse position in world coordinates Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); // set the indicator at the current mouse position vortexIndicator.transform.position = mousePos; // calculate the current radius based on the vortex scale float vortexScale = Mathf.Lerp(vortexMinScale, vortexMaxScale, vortexScaleProgress / vortexBuildTime) - 1; float radius = vortexBaseRadius + vortexRadiusGrowthRate * vortexScale; // scale the indicator based on the current radius vortexIndicator.transform.localScale = Vector2.one * radius * 2; // set the indicator color based on the current radius vortexIndicator.color = radius > vortexCrushRadiusThreshold ? vortexCrushIndicatorColor : vortexRegularIndicatorColor; } // upon releasing the left-click button if (Input.GetButtonUp("Fire1") && canSpawnVortex && isBuildingVortex) { // start the vortex spawn cooldown StartCoroutine(HandleVortexCooldown()); // stop building the vortex scale isBuildingVortex = false; // disable the visual indicator vortexIndicator.enabled = false; // get the current mouse position in world coordinates Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); // spawn a new vortex object at the mouse position Vortex vortex = Instantiate(vortexPrefab, mousePos, Quaternion.identity, spawnParent); // calculate the vortex stats based on the current vortex scale float vortexScale = Mathf.Lerp(vortexMinScale, vortexMaxScale, vortexScaleProgress / vortexBuildTime) - 1; float radius = vortexBaseRadius + vortexRadiusGrowthRate * vortexScale; float innerStrength = vortexBaseInnerStrength + vortexInnerStrengthGrowthRate * vortexScale; float outerStrength = vortexBaseOuterStrength + vortexOuterStrengthGrowthRate * vortexScale; // activate the vortex at the current vortex scale vortex.Activate(radius, innerStrength, outerStrength, vortexCrushForceThreshold, vortexCrushRadiusThreshold, vortexTargetLayers); // reset the scale progress vortexScaleProgress = 0; } // upon pressing the right-click button if (Input.GetButtonDown("Fire2") && isBuildingVortex) { // stop building the vortex scale isBuildingVortex = false; // disable the visual indicator vortexIndicator.enabled = false; // reset the scale progress vortexScaleProgress = 0; } }