Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
0
Question by mygoddess007700 · Sep 03, 2021 at 12:36 PM · gizmos

OnDrawGizmos() can not show boundary

I made a small plane and was going to add a boundary to the plane's range, and I chose OnDrawGizmos(), but I had a problem.


The problem is that I can't see the rectangle boundary I drew in my project panel.


This is my code. I put it on the plane. In fact, if I replace this code with some other simple boundary code, I can't see the boundary too.


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BoundsCheck : MonoBehaviour
 {
     [Header("Set Dynamically")]
     public float camWidth;
     public float camHeight;
 
     private void Awake()
     {
         camHeight = Camera.main.orthographicSize;
         camWidth = camHeight * Camera.main.aspect;
     }
 
     private void OnDrawGizmos()
     {
         if(!Application.isPlaying)
         {
             return;
         }
         Vector3 boundSize = new Vector3(camWidth * 2, camHeight * 2, 0.1f);
         Gizmos.DrawWireCube(Vector3.zero, boundSize);
     }
 }

And the Gizmos menu does have this script. alt text


Hope someone can give advice, if there is anything I need to add, please feel free to ask, thanks a million.

question.png (112.5 kB)
Comment
Add comment · Show 2
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 andrew-lukasik · Sep 03, 2021 at 03:01 PM 0
Share
 Gizmos.DrawWireCube(Vector3.zero, boundSize);

are you sure you want to draw this cube at (0,0,0) and not something like transform.position?

avatar image mygoddess007700 · Sep 04, 2021 at 06:07 AM 0
Share

I think I really want the origin to be the center. And even if I changed the origin to the current position of the plane, I still didn't see the boundary. I was very confused.

1 Reply

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

Answer by andrew-lukasik · Sep 04, 2021 at 09:04 AM

If the thing you want to just draw camera orthographic bounds, this is how you do that:

DrawCameraOgraphicBounds.cs

 using UnityEngine;
 public class DrawCameraOgraphicBounds : MonoBehaviour
 {
     [SerializeField] Camera _camera = null;
     void OnDrawGizmos ()
     {
         if( _camera!=null )
         {
             if( !_camera.orthographic )
             {
                 Debug.LogWarning("camera is not orthographic",gameObject);
                 return;
             }

             Gizmos.matrix = _camera.cameraToWorldMatrix;// special camera matrix
             {
                 float h = _camera.orthographicSize;
                 float w = h * _camera.aspect;
                 float near = _camera.nearClipPlane;
                 float far = _camera.farClipPlane;
                 Vector3 size = new Vector3( w*2 , h*2 , far-near );
                 Vector3 localOffset = new Vector3( 0 , 0 , -size.z*0.5f - near );
                 
                 Gizmos.color = new Color(0,1,0,0.05f); Gizmos.DrawCube( localOffset , size );
                 Gizmos.color = new Color(1,1,0,1); Gizmos.DrawWireCube( localOffset , size );
             }
         }
     }
 }
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 mygoddess007700 · Sep 04, 2021 at 11:32 AM 1
Share

Thank you very much. Thanks to your code, I wonder if there is a problem with my own project.

I reloaded the project layout and was surprised to find that everything worked out.

For some reason, my previous project layout caused my camera to lose even its edge lines.

In a word, you have successfully solved my problem, I wish you my best wishes.

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

125 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Labeling objects in the scene editor view 2 Answers

What do I need to change for each arrow to move the object only along one axis, for rotation to rotate only around one axis? 1 Answer

Unity 4.6 viewport problems 0 Answers

Editor Windows : Help required 1 Answer

How would you make a ray collide with a Gizmos sphere (float) 1 Answer


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