In the DelayedTargetingScript.cs, why don’t we just invoke the finish event when we have successfully captured the target, so when the action did not get cancelled, instead of checking it when we call the finish event first over in the Ability.cs within the TargetAcquired method? What could happen in between?
This is what I mean:
IEnumerator Targeting(AbilityData abilityData, PlayerControl playerControl, Action finished)
{
playerControl.enabled = false;
if (summonCirclePrefabInstance == null)
{
summonCirclePrefabInstance = Instantiate<Transform>(summonCirclePrefab);
}
summonCirclePrefabInstance.gameObject.SetActive(true);
summonCirclePrefabInstance.localScale = new Vector3(raycastRadius*2, 1, raycastRadius*2);
while (!abilityData.IsCancelled)
{
Cursor.SetCursor(cursorTexture, cursorHotspot, CursorMode.Auto);
if (Physics.Raycast(PlayerControl.GetMouseRay(), out RaycastHit raycastHit, 1000, layerMask))
{
summonCirclePrefabInstance.position = raycastHit.point;
if (Input.GetMouseButtonDown(0))
{
// Absorb the whole mouse click
yield return new WaitWhile(() => Input.GetMouseButton(0));
abilityData.TargetedPoint = raycastHit.point;
abilityData.GameObjects = GetGameObjectsInRadius(raycastHit.point);
finished?.Invoke();
break;
}
}
yield return null;
}
summonCirclePrefabInstance.gameObject.SetActive(false);
playerControl.enabled = true;
}