Yep.
In the OnLoad section of the scripts for your panel:
Code:
self:RegisterEvent("PLAYER_TARGET_CHANGED")
self:Hide()
this registers for our events and then hides the panel (cause we won't have a target when logging in)
Then in the OnEvent section:
Code:
if UnitExists("target") then
self:Show()
else
self:Hide()
end
this checks to see if we have a target when the event fires (since losing your target counts as a change). If we have a target, show our panel. If not, hide it.
Using PLAYER_TARGET_CHANGED is better than using UNIT_TARGET because it will fire only when you need it - running your code only when you need to.
A MUCH easier way to do what you want though... Is to not use scripts at all. Go to the area of the config where you set up the size/colors/etc. of your panel. Scroll all the way down. Set the target frame as the
parent of the panel. The panel will then inherit from the target frame things such as scale and
visibility. If you are using the default unit frames, the name of the frame is simply TargetFrame. Otherwise, use the /framestack command and hover your mouse over it to find what name to put in the box.