Have you ever crafted Unity C# code like this?
void ForceUpdateBackend()
{
StartCoroutine(ForceUpdateBackend_Internal(path: Url));
}
IEnumerator ForceUpdateBackend_Internal(string path)
{
var request = UnityWebRequest.Get(path);
yield return request.SendWebRequest();
Debug.Log(request.downloadHandler.text); // ...
}Somehow, it feels uncomfortable to have two different functions that do kind of the same thing.
Wait, you haven't written such code?
Okay, what about this pattern?
void AvoidCollision()
{
var penaltyLeft = CalculateCollisionPenalty(-transform.right);
var penaltyForward = CalculateCollisionPenalty(transform.forward);
var penaltyRight = CalculateCollisionPenalty(transform.right);
// drive towards the safest direction
// ...
}
int CalculateCollisionPenalty(Vector3 direction)
{
var didHit = Physics.Raycast(transform.position, direction, out RaycastHit hit);
if (didHit == false …