While you can do what Captain Pinapple suggested, Why do you actually check both TryGetComponent in a single if statement with an “or”, just to test the result of both individually again? This is completely redundant. Just do
if (go.TryGetComponent(out Collider col))
co = col;
if(go.TryGetComponent(out Rigidbody rb))
{
// do whatever you want with rb
}
Note: You have marked your Collider variable “co” with SerializeField, so this value is serialized and can be assigned in the inspector. However using TryGetComponent will always override what may have been serialized in that variable if the gameobject “go” has a Collider. So this whole bit of code looks confusing. If you want to set the collider through code, why serialize the field? If you want to implement some sort of fallback and only use TryGetComponent when you did not assign a collider in the inspector, you should do something like
if (co != null || go.TryGetComponent(out co))
{
// do something with the collider co.
}
This first checks if the collider was assigned in the inspector and only if it was not assigned, it tries to get the collider from the gameobject “go”. If that fails as well, the code in the if body will not execute since we don’t have a Collider.