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 fingerskater55 · Jan 24, 2014 at 03:20 AM · iosradar

Radar is not working... Why?

I have downloaded the classic Unity wiki radar script, and have seemed to set it up correctly on a game object. The problem is though, nothing happens on the radar. The center blip does not move, and enemies do not appear even though I have tagged them as "Enemy" I am developing for iOS, by the way. If you also know of any good free mobile radar scripts that do work that would be great if you could share them.

 public class Radar : MonoBehaviour
 {
     
     public enum RadarTypes : int {Textured, Round, Transparent};
     public enum RadarLocations : int {TopLeft, TopCenter, TopRight, BottomLeft, BottomCenter, BottomRight, Left, Center, Right, Custom};
     
     // Display Location
     public RadarLocations radarLocation = RadarLocations.BottomCenter;
     public Vector2 radarLocationCustom;
     public RadarTypes radarType = RadarTypes.Round;
     public Color radarBackgroundA = new Color(255, 255, 0);
     public Color radarBackgroundB = new Color(0, 255, 255);
     public Texture2D radarTexture;
     public float radarSize = 0.20f;  // The amount of the screen the radar will use
     public float radarZoom = 0.60f;
     
     // Center Object information
     public bool   radarCenterActive;
     public Color  radarCenterColor = new Color(255, 255, 255);
     public string radarCenterTag;
     
     // Blip information
     public bool   radarBlip1Active;
     public Color  radarBlip1Color = new Color(0, 0, 255);
     public string radarBlip1Tag;
     
     public bool   radarBlip2Active;
     public Color  radarBlip2Color = new Color(0, 255, 0);
     public string radarBlip2Tag;
     
     public bool   radarBlip3Active;
     public Color  radarBlip3Color = new Color(255, 0, 0);
     public string radarBlip3Tag;
     
     public bool   radarBlip4Active;
     public Color  radarBlip4Color = new Color(255, 0, 255);
     public string radarBlip4Tag;
     
     // Internal vars
     private GameObject _centerObject;
     private int        _radarWidth;
     private int        _radarHeight;
     private Vector2    _radarCenter;
     private Texture2D  _radarCenterTexture;
     private Texture2D  _radarBlip1Texture;
     private Texture2D  _radarBlip2Texture;
     private Texture2D  _radarBlip3Texture;
     private Texture2D  _radarBlip4Texture;
 
     // Initialize the radar
     void Start ()
     {
         // Determine the size of the radar
         _radarWidth = (int)(Screen.width * radarSize);
         _radarHeight = _radarWidth;
         
         // Get the location of the radar
         setRadarLocation();
         
         // Create the blip textures
         _radarCenterTexture = new Texture2D(3, 3, TextureFormat.RGB24, false);
         _radarBlip1Texture = new Texture2D(3, 3, TextureFormat.RGB24, false);
         _radarBlip2Texture = new Texture2D(3, 3, TextureFormat.RGB24, false);
         _radarBlip3Texture = new Texture2D(3, 3, TextureFormat.RGB24, false);
         _radarBlip4Texture = new Texture2D(3, 3, TextureFormat.RGB24, false);
         
         CreateBlipTexture(_radarCenterTexture, radarCenterColor);
         CreateBlipTexture(_radarBlip1Texture, radarBlip1Color);
         CreateBlipTexture(_radarBlip2Texture, radarBlip2Color);
         CreateBlipTexture(_radarBlip3Texture, radarBlip3Color);
         CreateBlipTexture(_radarBlip4Texture, radarBlip4Color);
         
         // Setup the radar background texture
         if (radarType != RadarTypes.Textured)
         {
             radarTexture = new Texture2D(_radarWidth, _radarHeight, TextureFormat.RGB24, false);
             CreateRoundTexture(radarTexture, radarBackgroundA, radarBackgroundB);
         }
         
         // Get our center object
         GameObject[] gos;
         gos = GameObject.FindGameObjectsWithTag(radarCenterTag);
         _centerObject = gos[0];
     }
     
     // Update is called once per frame
     void OnGUI ()
     {
         GameObject[] gos;
         
         // Draw th radar background
         if (radarType != RadarTypes.Transparent)
         {
             Rect radarRect = new Rect(_radarCenter.x - _radarWidth / 2, _radarCenter.y - _radarHeight / 2, _radarWidth, _radarHeight);
             GUI.DrawTexture(radarRect, radarTexture);
         }
         
         // Draw blips
         if (radarBlip1Active)
         {
             // Find all game objects
             gos = GameObject.FindGameObjectsWithTag(radarBlip1Tag); 
             
             // Iterate through them and call drawBlip function
             foreach (GameObject go in gos)
             {
                 drawBlip(go, _radarBlip1Texture);
             }
         }
         if (radarBlip2Active)
         {
             gos = GameObject.FindGameObjectsWithTag(radarBlip2Tag); 
             
             foreach (GameObject go in gos)
             {
                 drawBlip(go, _radarBlip2Texture);
             }
         }
         if (radarBlip3Active)
         {
             gos = GameObject.FindGameObjectsWithTag(radarBlip3Tag); 
             
             foreach (GameObject go in gos)
             {
                 drawBlip(go, _radarBlip3Texture);
             }
         }
         if (radarBlip4Active)
         {
             gos = GameObject.FindGameObjectsWithTag(radarBlip4Tag); 
             
             foreach (GameObject go in gos)
             {
                 drawBlip(go, _radarBlip4Texture);
             }
         }
         
         // Draw center oject
         if (radarCenterActive)
         {
             Rect centerRect = new Rect(_radarCenter.x - 1.5f, _radarCenter.y - 1.5f, 3, 3);
             GUI.DrawTexture(centerRect, _radarCenterTexture);
         }
     }
     
     // Draw a blip for an object
     void drawBlip(GameObject go, Texture2D blipTexture)
     {
         if (_centerObject)
         {
             Vector3 centerPos = _centerObject.transform.position;
             Vector3 extPos = go.transform.position;
             
             // Get the distance to the object from the centerObject
             float dist = Vector3.Distance(centerPos, extPos);
             
             // Get the object's offset from the centerObject
             float bX = centerPos.x - extPos.x;
             float bY = centerPos.z - extPos.z;
             
             // Scale the objects position to fit within the radar
             bX = bX * radarZoom;
             bY = bY * radarZoom;
             
             // For a round radar, make sure we are within the circle
             if(dist <= (_radarWidth - 2) * 0.5 / radarZoom)
             {
                 Rect clipRect = new Rect(_radarCenter.x - bX - 1.5f, _radarCenter.y + bY - 1.5f, 3, 3);
                 GUI.DrawTexture(clipRect, blipTexture);
             }
         }
     }
     
     // Create the blip textures
     void CreateBlipTexture(Texture2D tex, Color c)
     {
         Color[] cols = {c, c, c, c, c, c, c, c, c};
         tex.SetPixels(cols, 0);
         tex.Apply();
     }
     
     // Create a round bullseye texture
     void CreateRoundTexture(Texture2D tex, Color a, Color b)
     {
         Color c = new Color(0, 0, 0);
         int size = (int)((_radarWidth / 2) / 4);
         
         // Clear the texture
         for (int x = 0; x < _radarWidth; x++)
         {
             for (int y = 0; y < _radarWidth; y++)
             {
                 tex.SetPixel(x, y, c);
             }
         }
         
         for (int r = 4; r > 0; r--)
         {
             if (r % 2 == 0)
             {
                 c = a;
             }
             else
             {
                 c = b;
             }
             DrawFilledCircle(tex, (int)(_radarWidth / 2), (int)(_radarHeight / 2), (r * size), c);
         }
         
         tex.Apply();
     }
     
     // Draw a filled colored circle onto a texture
     void DrawFilledCircle(Texture2D tex, int cx, int cy, int r, Color c)
     {
         for (int x = -r; x < r ; x++)
         {
             int height = (int)Mathf.Sqrt(r * r - x * x);
             
             for (int y = -height; y < height; y++)
                 tex.SetPixel(x + cx, y + cy, c);
         }
     }
     
     // Figure out where to put the radar
     void setRadarLocation()
     {
         // Sets radarCenter based on enum selection
         if(radarLocation == RadarLocations.TopLeft)
         {
             _radarCenter = new Vector2(_radarWidth / 2, _radarHeight / 2);
         }
         else if(radarLocation == RadarLocations.TopCenter)
         {
             _radarCenter = new Vector2(Screen.width / 2, _radarHeight / 2);
         }
         else if(radarLocation == RadarLocations.TopRight)
         {
             _radarCenter = new Vector2(Screen.width - _radarWidth / 2, _radarHeight / 2);
         }
         else if(radarLocation == RadarLocations.Left)
         {
             _radarCenter = new Vector2(_radarWidth / 2, Screen.height / 2);
         }
         else if(radarLocation == RadarLocations.Center)
         {
             _radarCenter = new Vector2(Screen.width / 2, Screen.height / 2);
         }
         else if(radarLocation == RadarLocations.Right)
         {
             _radarCenter = new Vector2(Screen.width - _radarWidth / 2, Screen.height / 2);
         }
         else if(radarLocation == RadarLocations.BottomLeft)
         {
             _radarCenter = new Vector2(_radarWidth / 2, Screen.height - _radarHeight / 2);
         }
         else if(radarLocation == RadarLocations.BottomCenter)
         {
             _radarCenter = new Vector2(Screen.width / 2, Screen.height - _radarHeight / 2);
         }
         else if(radarLocation == RadarLocations.BottomRight)
         {
             _radarCenter = new Vector2(Screen.width - _radarWidth / 2, Screen.height - _radarHeight / 2);
         }
         else if(radarLocation == RadarLocations.Custom)
         {
             _radarCenter = radarLocationCustom;
         }
     } 
     
     
 }
 
Comment
Add comment · Show 1
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 HuskyPanda213 · Jan 24, 2014 at 03:41 AM 0
Share

I do not really know what is wrong(sorry :( ).

Though just saying, you may want to program your own system, this one seems highly un-optimized for mobile/ios. Anything using ongui on ios is typically not good for performance.

0 Replies

· Add your reply
  • Sort: 

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

19 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

Related Questions

Graphics Problems on iOS 4.x 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

When will Chinese fix be ported to 4.6 (IOS 9)? 0 Answers

Unity SplashScreen wrong orientation iOS 4 Answers

Splashscreen problem on iOS 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