Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 SamuelJZito · Nov 25, 2016 at 07:57 AM · build-errorandroid buildcollider2dpolygon collider 2d

When my project is built my polygon collider does not change.

In the editor everything works perfectly, including the faulty PG collier. It goes to ducking mode when you Duck, and normal mode when you are not. When it is built however, it only ever stays in its normal mode. If it helps here is my code:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections; 
 public class Player_Controls : MonoBehaviour {
     public float speed, Jump, SpeedIncreaseIncriments, DuckingTime;
     public GameObject Death_TapToRestart, Death_Quit, Death_Pick;
     [HideInInspector]
     public bool canMove = true, canJump = false;
     //Ducking is for Phones
     bool CanDuck = true, Ducking = false;
     float ypos;
     Animator anim;
     PolygonCollider2D PG;
     [HideInInspector]
     public Vector2[] WalkingPoints, DuckingPoints;
     [HideInInspector]
     public int Option;
 
     float DuckingTIME;
  void Start() {
         DuckingTIME = DuckingTime;
         PG = GetComponent<PolygonCollider2D>();
         anim = GetComponent<Animator>();
         canMove = true;
         ypos = transform.position.y;
     }
     //Changes Speed
     void Speed() {
         if (Mathf.Round(transform.position.x % 100) == 0) {
             speed += SpeedIncreaseIncriments;
         }
     }
     //Sees if you are dead.
     void OnCollisionEnter2D(Collision2D col) {
         if (col.gameObject.layer == 9) {
             canMove = false;
         }
     }
     void Update() {
         if (canMove) {
             //Are you on the ground?
             if (transform.position.y <= ypos) {
                 //yes
                 canJump = true;
             } else {
                 //no
                 canJump = false;
             }
             //Falling through the World?
             if (transform.position.y <= -5) {
                 canMove = false;
             }
 
 
           //  #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER
 
             //Key Binded!
             DUCK();
             //Key Binded!
             JUMP();
 
             //#else 
 
             //Swipe Controls       
             if (Swiping()== "Jump") {
                 if (canJump) {
                     GetComponent<Rigidbody2D>().AddForce(new Vector2(0, Jump));
                 }
             }
             if (Swiping()=="Drag") {
                 Ducking = true;
             }
 
             if(Swiping() == "unDuck") { 
                 Ducking = false;
             }
             
 
 
 
             if (Ducking) {
                 PG.SetPath(0, DuckingPoints);
                 anim.SetBool("Ducking", true);
                 DuckingTime -= Time.deltaTime;
                 if (DuckingTime <= 0) {
                     DuckingTime = DuckingTIME;
                     anim.SetBool("Ducking", false);
                     PG.SetPath(0, WalkingPoints);
                     Ducking = false;
                 }
             }                  
  //           #endif
 
 
             //UI STuff
             Death_TapToRestart.SetActive(false);
             Death_Quit.SetActive(false);
             Death_Pick.SetActive(false);
             //End UI Stuff
             anim.SetBool("Dead", false);
             Camera.main.transform.Translate(new Vector3(speed * Time.deltaTime, 0, 0));
             transform.Translate(new Vector3(speed * Time.deltaTime, 0, 0));
         } else {
             //UI 
             Death_TapToRestart.SetActive(true);
             Death_Quit.SetActive(true);
             Death_Pick.SetActive(true);
             //End UI Stuff
             anim.SetBool("Dead", true);
             //                GameObject.Find("World Generator").GetComponent<World_Generation>().Restart();
             
         }
     }
 
 
     private Vector2 touchOrigin = -Vector2.one;
     string Swiping() {
         float y = 0;
         if (Input.touchCount > 0) {
             Touch myTouch = Input.touches[0];
             if (myTouch.phase == TouchPhase.Began) {
                 touchOrigin = myTouch.position;
             } else if (myTouch.phase == TouchPhase.Ended && touchOrigin.x >= 0) {
                 Vector2 TouchEnd = myTouch.position;
                 y = TouchEnd.y - touchOrigin.y;
                 if (y <= -10f) {
                     return "Drag";
                 }
                 if (y >= 10f) {
                     return "Jump";
                 }
                 return "Jump";
             }
         }
         return null;
     }
     void JUMP() {
         if (canJump) {
             if (Input.GetButton("Jump")) {
                 GetComponent<Rigidbody2D>().AddForce(new Vector2(0, Jump));
             }
         }
     }
     //Keybinded Duck
     void Duck() {
         if (Input.GetButton("Duck")) {
             anim.SetBool("Ducking", true);
             PG.SetPath(0, DuckingPoints);
         }
         if (Input.GetButtonUp("Duck")) {
             anim.SetBool("Ducking", false);
             PG.SetPath(0, WalkingPoints);
         }
     }
     void DUCK() {
         if (CanDuck) {
             Duck();
         }
     }
 }
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

Answer by SamuelJZito · Dec 12, 2016 at 02:32 PM

I have fixed it myself thanks to this link: https://www.reddit.com/r/Unity2D/comments/2ge8h0/altering_a_polygon_collider_at_runtime/ and this comment: IMPORTANT: If you want to modify Polygon Colliders based on the shape of a sprite at runtime make sure you set the sprite to "Advanced" and check off "Readable". If you don't do this the collider will work in the editor but not in any builds.

I learned this during the last hour of a game jam when all my colliders broke in the web build...

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity freezing when trying to build to android? 0 Answers

Unity won't export for android 0 Answers

I have a build problem android. 0 Answers

Unauthorized access exeption when building to Oculus quest 2 0 Answers

build-error 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