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 /
avatar image
0
Question by Mayflower · May 18, 2015 at 10:18 AM · objectsmapzoomworlddetail

How Do I Make An Object Appear ONLY When I've Zoomed In Close Enough

Ok, here's my example.

I have a world map with different regions. When the camera is zoomed completely out, the viewer sees only the basic map, however when the user zooms closer, I want the different region names to appear as the camera gets closer.

It's a level of detail issue that I can't quite figure out on my own. I have the region names as objects, is this the best way?

Regards, Jessica

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 $$anonymous$$ · May 18, 2015 at 10:26 AM 0
Share

If you're using an orthographic camera and using the size as the zoom, then you could just check when the size is smaller than x and show the objects.

If you only have one camera and it is tagged as "$$anonymous$$ain Camera" then you can use Camera.main to get a reference to it.

avatar image $$anonymous$$ · May 18, 2015 at 10:51 AM 0
Share

Based on the number of differing answers I think we can come to the conclusion that your question is a bit vague. If we have already managed to answer your question then please mark the correct solution as the answer. If not then perhaps posting how your zoo$$anonymous$$g in/out as well as the type of camera might be useful.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Molehole · May 18, 2015 at 10:45 AM

You could do a script which counts distance between your camera and the object

 Vector3.distance(object.transform.position, camera.transform.position);

and then turns rendering on and off depending if the distance is larger than your chosen view distance.

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 fafase · May 18, 2015 at 07:00 PM 0
Share

Again, this is only valid if the zoom is made with a movement of the camera (which is not the right way to do but well...who does things right anyway...?)

avatar image
0

Answer by fafase · May 18, 2015 at 10:35 AM

http://forum.unity3d.com/threads/this-script-gives-you-objects-screen-size-in-pixels.48966/

 float DistanceAndDiameterToPixelSize(float distance, float diameter){
        
     float pixelSize = (diameter * Mathf.Rad2Deg * Screen.height) / (distance * Camera.main.fieldOfView);
     return pixelSize;
 }

then you can define that if greater than a threshold => render object.

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
avatar image
0

Answer by Cherno · May 18, 2015 at 10:35 AM

You need to keep track of the region name objects, for example by keeping references to them in an array or List of type GameObject. You then need to continually check the distance from the camera's position to each region name object, via Vector3.Distance. If the distance is less than a set threshold, you access that region name object's Renderer component and enable it, otherwise you disable it.

Here is a sample script, it's meant to be attached to the camera gameobject.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class TrackDetailObjects : MonoBehaviour {
      public List<GameObject> detailObjects = new List<GameObject>();//fill this list via the inspector or via script with the region name objects
 
      public float detailThreshold = 50f;
 
      void Update() {
            CheckDistances();
      }
 
      private void CheckDistances() {

           foreach(GameObject go in detailObjects) {
                float distance = Vector3.Distance(transform.position, go.transform.position);
                if(distance < detailThreshold) {
                     Renderer renderer = go.GetComponent<Renderer>();
                     if(renderer != null && renderer.enabled == false) {
                          renderer.enabled = true;
                     }
                }
                else {
                     Renderer renderer = go.GetComponent<Renderer>();
                     if(renderer != null && renderer.enabled == true) {
                          renderer.enabled = false;
                     }
                }
           }
      }
 }


Note that this is not the most efficient code as it accesses the Renderer component of all objects each frame, but it's good enough to get you started and shouldn't affect performance.

Comment
Add comment · Show 2 · 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 fafase · May 18, 2015 at 10:41 AM 0
Share

That is only valid if the zoom is a movement of the camera, if the zoom is based on FOV, as should be, this would not work since the distance remains the same.

avatar image Cherno · May 18, 2015 at 10:52 AM 0
Share

Ah yes, you are right, I didn't think about the fov. Still, the same theory holds true. Ins$$anonymous$$d of the distance, you compare the fov with the threshold.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Change from one scene to another 0 Answers

Can I make an open world with this engine? 1 Answer

Possibility to draw objects with real world measurements? 1 Answer

I am writing a camera script, but it seems not to be working. Any suggestions? 1 Answer

How should you make an MMORPG world? 3 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