Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by Popoco · Sep 24, 2010 at 08:12 PM · cameragizmos

Rule of Thirds Camera Gizmo

I would like some help creating Gizmo for the camera that draws the rule of thirds on screen(Divide the screen into 9 sections). So far I have the following script attached to the main camera (but it always draws my test line way off the game camera)

var vStart : Vector3; function OnDrawGizmosSelected () {

 Gizmos.color = Color.red;
 vStart = transform.position; 
 vStart.x -= Screen.width /3;
 Gizmos.DrawRay (vStart, Vector3.up * 55);  

}

alt text

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by skovacs1 · Sep 24, 2010 at 09:42 PM

Would something like this work?

var screenOffset : float = 0.001;

function OnDrawGizmosSelected () { Gizmos.color = Color (1,0,0,.5);

 //Figure out how big to make things
 var zero = camera.ScreenPointToRay(Vector3(0,0,0)).GetPoint(screenOffset);
 var right = camera.ScreenPointToRay(Vector3(Screen.width,0,0)).GetPoint(screenOffset);
 var up = camera.ScreenPointToRay(Vector3(0,Screen.height,0)).GetPoint(screenOffset);
 var upDirection = transform.up * (up - zero).magnitude;
 var rightDirection = transform.right * (right - zero).magnitude;

 //Get our points away from the screen
 var bottomLeft =
       camera.ScreenPointToRay(Vector3(Screen.width/3,0,0)).GetPoint(screenOffset);
 var bottomRight = 
       camera.ScreenPointToRay(Vector3(2*Screen.width/3,0,0)).GetPoint(screenOffset);
 var leftBottom = 
       camera.ScreenPointToRay(Vector3(0,Screen.height/3,0)).GetPoint(screenOffset);
 var leftTop = 
       camera.ScreenPointToRay(Vector3(0,2*Screen.height/3,0)).GetPoint(screenOffset);

 //Draw
 Gizmos.DrawRay(bottomLeft, upDirection);
 Gizmos.DrawRay(bottomRight, upDirection);
 Gizmos.DrawRay(leftBottom, rightDirection);
 Gizmos.DrawRay(leftTop, rightDirection);

}

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Popoco · Sep 24, 2010 at 10:11 PM 0
Share

Yes it did, Wow thank you very much, you saved my day.

avatar image
1

Answer by $$anonymous$$ · Oct 14, 2016 at 03:06 PM

If you need in c#

 public class RulesOfThirds : MonoBehaviour {
 
     public bool enableGizmosRules = false;
     public bool enableDebugRules = false;
     public float screenOffSet = 0.001f;
 
     private Camera cameraMain;
 
     // Use this for initialization
     void Start () {
         cameraMain = GetComponent<Camera> ();
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnDrawGizmosSelected(){
         Gizmos.color = Color.yellow;
 
         Vector3 zero = cameraMain.ScreenPointToRay (new Vector3 (0, 0, 0)).GetPoint (screenOffSet);
         Vector3 right = cameraMain.ScreenPointToRay (new Vector3 (Screen.width, 0, 0)).GetPoint (screenOffSet);
         Vector3 up = cameraMain.ScreenPointToRay (new Vector3 (0, Screen.height, 0)).GetPoint (screenOffSet);
 
         Vector3 upDirection = transform.up * (up - zero).magnitude;
         Vector3 rightDirection = transform.right * (right - zero).magnitude;
 
         Vector3 bottomLeft = cameraMain.ScreenPointToRay (new Vector3 (Screen.width / 3, 0, 0)).GetPoint (screenOffSet);
         Vector3 bottomRight = cameraMain.ScreenPointToRay (new Vector3 (2 * Screen.width / 3, 0, 0)).GetPoint (screenOffSet);
         Vector3 RightTop = cameraMain.ScreenPointToRay (new Vector3 (0,Screen.height / 3, 0)).GetPoint (screenOffSet);
         Vector3 LeftTop = cameraMain.ScreenPointToRay (new Vector3 (0, 2 * Screen.height / 3, 0)).GetPoint (screenOffSet);
 
         if (enableDebugRules) {
             Gizmos.DrawRay (bottomLeft, upDirection);
             Gizmos.DrawRay (bottomRight, upDirection);
             Gizmos.DrawRay (RightTop, rightDirection);
             Gizmos.DrawRay (LeftTop, rightDirection);
         }
         if (enableDebugRules) {
             Debug.DrawRay (bottomLeft, upDirection, Color.yellow);
             Debug.DrawRay (bottomRight, upDirection, Color.yellow);
             Debug.DrawRay (RightTop, rightDirection, Color.yellow);
             Debug.DrawRay (LeftTop, rightDirection, Color.yellow);
         }
 
     } 
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Zooming in to a certain area of UI 0 Answers

Please help me with this error 2 Answers

Change shown scene from loaded scenes? 0 Answers

I want my camera to move only Y axis and my character to rotate with my camera 0 Answers

i am trying to work with wheel collides and i am having some problems 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges