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 furybam · Jun 07, 2021 at 02:41 PM · errorcollider2dfatal error

Polygon Collider 2D Fatal Error

I have problem with polygon collider 2D

 public class provinceManager : MonoBehaviour
 {
     public Transform[] provinces;
     public bool isFirstLaunch;
     public Texture2D map;
     private Color currentColor;
 
     private (int, int) startX = (0, 0);
     private (int, int) endX = (0, 0);
     private (int, int) startY = (0, 0);
     private (int, int) endY = (0, 0);
 
     void Start()
     {
         isFirstLaunch = true;
     }
     void Update()
     {
         if (isFirstLaunch == true)
         {
             for (int i=0;i<provinces.Length;i++)
             {
                 map = provinces[i].gameObject.GetComponent<provinceController>().worldMap;
                 currentColor = provinces[i].gameObject.GetComponent<provinceController>().color;
                 Color[] c = map.GetPixels(0, 0, map.width, map.height);
                 Texture2D v2worldmap = new Texture2D(map.width, map.height);
                 for (int index = 0; index < c.Length; index++)
                 {
                     if (c[index] != currentColor)
                     {
                         c[index] = Color.clear;
                     }
                 }
                 v2worldmap.SetPixels(c);
                 for (int y = 0; y < map.height; y++)
                 {
                     for (int x = 0; x < map.width; x++)
                     {
                         if (v2worldmap.GetPixel(x, y) != Color.clear)
                         {
                             if (v2worldmap.GetPixel(startX.Item1, startX.Item2) == Color.clear)
                             {
                                 startX = (x, y);
                                 endX = (x, y);
                             }
                             if (v2worldmap.GetPixel(startY.Item1, startY.Item2) == Color.clear)
                             {
                                 startY = (x, y);
                                 endY = (x, y);
                             }
                             if (startX.Item1 >= x)
                             {
                                 startX = (x, y);
                             }
                             if (endX.Item1 <= x)
                             {
                                 endX = (x, y);
                             }
                             if (startY.Item1 >= y)
                             {
                                 startY = (x, y);
                             }
                             if (endY.Item1 <= y)
                             {
                                 endY = (x, y);
                             }
                         }
                     }
                 }
                 v2worldmap.Apply();
                 v2worldmap.filterMode = FilterMode.Point;
                 Rect rec = new Rect(startX.Item1-1f, startY.Item2+2f, endX.Item1-startX.Item1+3f, endY.Item2-startY.Item2-3f);
                 float posX = (startX.Item1 + endX.Item1) / 2f - (map.width / 2f);
                 float posY = (startY.Item2 + endY.Item2) / 2f - (map.height / 2f);
                 Vector2 newPos = new Vector2(posX, posY);
                 provinces[i].transform.Translate(newPos,Space.World);
                 provinces[i].gameObject.GetComponent<SpriteRenderer>().sprite = Sprite.Create(v2worldmap, rec, new Vector2(0.5f, 0.5f), 1f);
                 PolygonCollider2D collider = provinces[i].gameObject.AddComponent<PolygonCollider2D>() as PolygonCollider2D;
             }
             isFirstLaunch = false;
         }
     }
 }

When I start play mode it shows an error alt text

I want to add component polygon collider 2d to the object with this sprite alt text

No information about this problem in the internet

How to fix it?

province.png (13.0 kB)
fatalerror.png (7.3 kB)
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

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

162 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 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

Unity 5 fatal error 3 Answers

"Fatal error! CheckDisalowAllowcation" when making a huge 2d array 2 Answers

Fatal Error, Unity crashes when opening project. 0 Answers

Physics Manager Error 0 Answers

I'm building PacMan game by tutorial and getting error: `Property collider2D has been deprecated. Use GetComponent() instead.' But when I use GetComponent I get another error. What should I use instead? 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