The issue in this line: Debug.Log("check" + unit==null);
You're not testing whether unit is null as you might think. Instead, due to operator precedence, this statement is being evaluated like this: Debug.Log(("check" + unit) == null);
Correct Way to Check for Null: If you want to check whether unit is null and log the result, you should explicitly use parentheses to ensure the comparison happens first:
Debug.Log("check " + (unit == null));
Always use parentheses when combining comparisons and concatenation in a debug log to avoid confusion: Debug.Log("Is unit null? " + (unit == null));