小编Dra*_*wgo的帖子

为什么 ReSharper 不建议对这两个块使用空传播?

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)

我错过了什么吗?我会为这两个块使用空传播。

c# resharper unity-game-engine

6
推荐指数
2
解决办法
5304
查看次数

标签 统计

c# ×1

resharper ×1

unity-game-engine ×1