GUICam

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m
(Removing all content from page)
Line 1: Line 1:
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"))
 

Revision as of 18:37, 19 October 2009

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox