ReSharper 建议对“可损坏”的 if 块使用空传播,但对于“forceVelocityCalculator”没有建议。
void Damage(Collider hitCollider)
{
var damageable = hitCollider.GetComponent<IDamageable>();
if (damageable != null)
{
damageable.TakeDamage(_damage);
}
}
void Push(Collider hitCollider)
{
var forceVelocityCalculator = hitCollider.GetComponent<ForceVelocityCalculator>();
if (forceVelocityCalculator != null)
{
forceVelocityCalculator.Push(_pushForce, GameAPI.playerTransform.transform.forward);
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?我会为这两个块使用空传播。