If you want to generate the unit delay variable in the model as a global variable, but not as an extern variable means that you would like to configure the unit delay as a static variable (with no declaration in the H file, but scope only in the C file). Open the unit delay block and give a unique name to the state attributes. Then as shown in figure, check the "state must resolve to simulink signal" box.
Now you must create a Simulink.Signal object of the same unique identifier in the Matlab workspace and set the storage class as "FileScope". This tells the code generator that the resolved signal is restricted only to a single file. So extern declarations are not required. Eg: UD = Simulink.Signal; UD.StorageClass = 'FileScope (Custom)'
Build the model/Generate code. You'll find that the delay block is now generated as variable "UD" and it's declared on top of the C file as static.
Hope it helps.