Are you moving the camera position as well?
You can use Input.mousePosition to get the location of your mouse on each frame.
http://docs.unity3d.com/Documentation/ScriptReference/Input-mousePosition.html
var relative = gun.position - Input.mousePosition;
gun.rotation = Quaternion.Euler(0,0, Mathf.Atan2(relative.y, relative.x) * Mathf.Rad2Deg);
You'll have to align your coordinate systems with this though.
http://docs.unity3d.com/Documentation/ScriptReference/Mathf.Atan2.html
↧