Can't compare distanceToEnemy and attackRange

When I try to compare distanceToEnemy and attackRange in this code:

        var distanceToEnemy = (targetEnemy.position, objectToPan.position);
        if (distanceToEnemy <= attackRange)
        {
        }

I get this error:
Cannot apply operator '<=' to operands of type '(UnityEngine.Vector3, Unity Engine.Vector3)' and 'float'

What should I do to fix this?

It seems to be fixed by me just replacing the if statement with:

        if (Vector3.Distance(targetEnemy.position, objectToPan.position) <= attackRange)
        {
        }

Double fixed it by extracting the if statement out into:

var distanceToEnemy = Vector3.Distance(targetEnemy.position, objectToPan.position);
if (distanceToEnemy <= attackRange)
{
}

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms