GUICam

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Removing all content from page)
m (Reverted edits by Joseph05408 (Talk); changed back to last version by DGuy)
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 19:08, 19 October 2009

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"))
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox