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 kitommy · Sep 03, 2015 at 09:28 AM · 2d-platformer2d-gameplayboxcollider2d

Problem with platformer game

I have a group of objects ( each object has Boxcollider2D ) with 1 leaders I have the Platform ( Platform offers Boxcollider2D each ) located in two different layer I want my group when running on a platform of layer 1 can jump onto the platform of layer 2 I checked the location of the platform under layer 2 ( if it is smaller than the position of my leader , the Box Collider is enabled , even if smaller , the disabled )
But the problem is that only leaders can jump onto the platform of layer 2 remaining members of the group were stranded because of the platform BoxCollider layer 2 has been enabled
How can i Fix that??

//My Platform of layer 2 script

 public class PlatformLayer2 : MonoBehaviour
 {
     public GameObject target;
     BoxCollider2D box;
     // Use this for initialization
     void Awake ()
     {
         target = GameObject.Find ("ground0");
         box = this.gameObject.GetComponent<BoxCollider2D> ();
     }
     void Start ()
     {
     
     }
     
     // Update is called once per frame
     void Update ()
     {
 
         target = GameObject.Find ("ground0");
         if (target != null) {
             if (transform.position.y < target.transform.position.y) {
                 box.enabled = true; 
             }
             if (transform.position.y >= target.transform.position.y)
                 box.enabled = false;
         }
     }
 }

//my ground with 1 leader script

 public class Mygroup : MonoBehaviour
 {
     public float time;
     public float jump;
     public bool grounded;
     public GameObject target;
     public string targetName;
     public Transform ground;
     public bool isDie, jumping;
 
     public float speed;
     Animator anim;
     // Use this for initialization
     void Awake ()
     {
         isDie = false;
     }
     void Start ()
     {
         Debug.Log ("Da tim thay target" + targetName);
         target = GameObject.Find (targetName);
         anim = GetComponent<Animator> ();
     }
     void FixedUpdate ()
     {
         if (this.gameObject.name == "P0") {
             targetName = "";
             Transform g = this.gameObject.transform.FindChild ("ground");
             if (g != null)
                 g.gameObject.name = "ground0";
         } else if (this.gameObject.name == "P1")
             targetName = "P0";
         else if (this.gameObject.name == "P2")
             targetName = "P1";
         else if (this.gameObject.name == "P3")
             targetName = "P2";
         else if (this.gameObject.name == "P4")
             targetName = "P3";
         else if (this.gameObject.name == "P5")
             targetName = "P4";
         else if (this.gameObject.name == "P6")
             targetName = "P5";
         else if (this.gameObject.name == "P7")
             targetName = "P6";
         else if (this.gameObject.name == "P8")
             targetName = "P7";
         else if (this.gameObject.name == "P9")
             targetName = "P8";
         else if (this.gameObject.name == "P10")
             targetName = "P9";
         else if (this.gameObject.name == "P11")
             targetName = "P10";
         
         target = GameObject.Find (targetName);
     }
     // Update is called once per frame
     void Update ()
     {
     
         Physics2D.IgnoreLayerCollision (9, 9);
         float dir = new float ();
         if (target != null)
             dir = target.transform.position.x - gameObject.transform.position.x;
         
         if (dir > 0.5f && grounded) {
             gameObject.transform.Translate (Vector2.right * speed);
         }
 
         grounded = Physics2D.Linecast (transform.position, ground.position, 1 << LayerMask.NameToLayer ("ground"));
         if (grounded) {
             jumping = false;
         }
         if (Input.GetMouseButtonDown (0) && gameObject.name == "P0" && grounded) {
             jumping = true;
             rigidbody2D.velocity = new Vector3 (0, 50 * jump, 0);
         }
         if (target != null && grounded && target.GetComponent<Mygroup> ().jumping && dir <= 2f) {
     
             StartCoroutine (Jump ());
         }
 
         anim.SetBool ("run", grounded);
 
     }
     IEnumerator Jump ()
     {
         yield return new WaitForSeconds (time);
         jumping = true;
         rigidbody2D.velocity = new Vector3 (0, 50 * jump, 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

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

2 People are following this question.

avatar image avatar image

Related Questions

BoxCollider doesnt change position when I flip the player! 1 Answer

Is it possible to make a game that looks 2d in Unity? 3 Answers

Having some stuck issues on the 2D infinite runner 0 Answers

How to store remaining durability of tiles? Tilemap 0 Answers

Bumper physics not working, 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