You could try:
GameObject targetObject = target.gameObject;
if (targetObject.activeSelf) {
}
and
targetObject.SetActive(true );
Also, the code block you showed is not well formed, you have an
else
statement outside of any function nor related to any
if
statement. I would be surprised this would even compile.