From Unify Community Wiki
Revision as of 19:08, 19 October 2009 by NCarter
Here is the script I attach to a camera that holds a Rect with the cameras pixels in GUI co-ordinate space.
import UnityEngine class GUICam (MonoBehaviour): public GUIRect as Rect cam as Camera def Start(): cam = transform.camera def Update (): pr=cam.pixelRect r = cam.rect screenHeight = pr.height / r.height GUIRect = Rect(pr.left,screenHeight-(pr.top+pr.height),pr.width,pr.height)
to use I put this on GUI generation script which is a camera component and draw a button in the top left of the camera viewport.
aGUICam as GUICam def Start (): aGUICam = transform.camera.GetComponent(GUICam) def ButtonGUI(): r=aGUICam.GUIRect GUI.Button ( Rect (r.xMin+10,r.yMin+50,50, 30), "button"))