• 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
1
Question by Punkjim420 · Mar 23, 2014 at 11:04 PM · cameramapcleanup

Screen pos out of view frustrum, Minimap Cleanup

I made a Minimap, or "Radar" that shows the entire world in my game.

This map can change size depending on what you use for the camSize variable in game. set it to 0 makes the frustrum error appear. Another thing my camera does is that it errors if i dont enter a value for camSize, so if camSize is empty i force the digit 1 to be my camSize, however for a brief second i get another error.

I understand why. My question is, is my scripting ok or should i do something different? Im not an advanced coder so i dont know if i should ignore the errors or find a work around.

If anyone wants to see the code:

 using UnityEngine;
 using System.Collections;
 using System.Text.RegularExpressions;
 
 public class Maps : MonoBehaviour {
 
     public Camera worldMap;
     public bool mapOpen = false;
     private string camSize = "1000";
     public GUISkin customSkin;
     void Start () {
         mapOpen = false;
     }
     void Update(){
         if(Input.GetKeyUp (KeyCode.M)){
             mapOpen = !mapOpen;
         }
 }
     void OnGUI(){
         GUI.skin = customSkin;
         if(camSize == "" || camSize == "."){
             camSize = "1";
         }
         if(mapOpen){
             GUI.Label(new Rect(Screen.width / 2 - 10, Screen.height / 2 - 10, 20, 20),"▲");
             worldMap.rect = new Rect (0, 0, 1, 1);
             camSize = GUI.TextField (new Rect(Screen.width - 50, Screen.height - 20, 50, 20), camSize);
             camSize = Regex.Replace(camSize, @"[^0-9.]", "");
             float temp = float.Parse(camSize);
                 worldMap.orthographicSize = temp;
         }
         if(!mapOpen){
             worldMap.rect = new Rect (0, 0, 0, 0);
             
         }
     }
 }
 
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

1 Reply

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

Answer by Bunny83 · Mar 23, 2014 at 11:46 PM

Instead of line 29 and 30 you should do something like this:

 float temp;
 if (float.TryParse(camSize, out temp))
 {
     worldMap.orthographicSize = temp;
 }

edit
In addition you could / should wrap the whole part with an "GUI.changed"-if like this:

 camSize = GUI.TextField (new Rect(Screen.width - 50, Screen.height - 20, 50, 20), camSize);
 if (GUI.changed)
 {
     camSize = Regex.Replace(camSize, @"[^0-9.]", "");
     float temp;
     if (float.TryParse(camSize, out temp))
     {
         worldMap.orthographicSize = temp;
     }
 }

This avoids unnecessary parsing (which would otherwise happen 2 times each frame) and setting of the orthographicSize (which will probably cause the camera's internal matrix to be recalculated).

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 Bunny83 · Mar 23, 2014 at 11:49 PM 0
Share

ps: Do you need to have an input field for the size? Usually it's more convenient to display a slider

avatar image Punkjim420 · Mar 24, 2014 at 06:33 AM 0
Share

I do not, ill probably convert to sliders because it seems odd to use a text field now that you have mentioned it. Thanks for your input. Ill try doing what you said.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Minimap enemy icon help? 0 Answers

How to Create a Multi Floor Mini Map 1 Answer

UnityPlayer in an Android MapActivity 3 Answers

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

Camera fails in build 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