The problem when you do \def\@unit#1 is that the argument will never be the brace, but all that goes from the open brace to the matching closed one and your test is never successful.
You can do it with \futurelet, but you'll be tied to a very inflexible system of input. Here's an expl3 implementation that's possibly clearer than \futurelet.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\unit}{}
{
% if we're not in math mode open it and remember to close it
\mode_if_math:F { $ \bool_set_true:N \l_merzong_close_bool }
% clear the container for the units
\seq_clear:N \merzong_units_seq
% start looking forward for an open brace
\merzong_scan_arg:
}
\cs_new_protected:Npn \merzong_scan_arg:
{
\peek_catcode:NTF \c_group_begin_token
{% the next token is an open brace, absorb the argument
\merzong_add_unit:n
}
{% the next token is not an open brace, deliver the units
% absorbed so far, with \unitmulti between them
\seq_use:Nn \merzong_units_seq { \unitmulti }
% close math mode if we started it
\bool_if:NT \l_merzong_close_bool { $ }
}
}
\cs_new_protected:Npn \merzong_add_unit:n #1
{
% absorb the argument and add it to the sequence
\seq_put_right:Nn \merzong_units_seq { \mathrm{#1} }
% restart the recursion
\merzong_scan_arg:
}
\seq_new:N \merzong_units_seq
\ExplSyntaxOff
\newcommand\useunitmultidot{\let\unitmulti=\cdot}
\newcommand\useunitmultispace{\let\unitmulti=\,}
\useunitmultidot % initialize
\begin{document}
\section{Centered dot}
\unit{kg}{m^2}{s^{-2}}
\section{Space}
\useunitmultispace
\unit{kg}{m^2}{s^{-2}}
\end{document}

What you want to do is already done by siunitx. Using it ensure great consistency in your usage of units.
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\section{Centered dot}
\sisetup{inter-unit-product=\ensuremath{{}\cdot{}}}
\SI{3}{\kilo\gram\meter\squared\per\second\squared} or \SI{3}{kg.m^2.s^{-2}}
\section{Thin space}
\sisetup{inter-unit-product=\,}
\SI{3}{\kilo\gram\meter\squared\per\second\squared} or \SI{3}{kg.m^2.s^{-2}}
\section{Fraction for negative exponent}
\sisetup{per-mode=symbol}
\SI{3}{\kilo\gram\meter\squared\per\second\squared}
\end{document}

siunitx. – jon May 23 '15 at 17:29\unit. One function is that I want to change connector between base units by\def\useunitmultidot{\let\unitmulti=\cdot} \def\useunitmultispace{\let\unitmulti=\ }and then declaring\useunitmultidotor\useunitmultispace(in this case,\cdotin the question becomes\unitmulti.). The other is that I want to give\unitan optional parameter in order to choose whether or not to enclose the unit in brackets. These are why I want to define\unitinstead of usingsiunitx. – Merzong May 23 '15 at 17:51siunitx, that has many more features. – egreg May 23 '15 at 18:01