[Unity][2D] 爬上绳索怎么站上平台

 

 

平台采用的Collider2D,使用下面的代码

要爬绳索,上平台的时候

Physics2D.IgnoreCollision(platform, other,true);

没有爬绳索,不 忽视 平台的Collider2D

Physics2D.IgnoreCollision(platform, other,false);

 

...
    void OnTriggerEnter2D(Collider2D other)
    {
        //Debug.Log("    OnTriggerEnter2D");
        if (other.tag == "Player"
            && other.GetComponent() != null
            && platform != null)
        {
            avaterControl = other.GetComponent();
            avaterControl.canLadder = true;
            Physics2D.IgnoreCollision(platform, other,true);
            //Debug.Log("    canLadder = true");
        }//

    }//OnTriggerEnter


    void OnTriggerExit2D(Collider2D other)
    {
        //Debug.Log("    OnTriggerExit2D");
        if (other.tag == "Player"
            && other.GetComponent() != null
            && platform != null)
        {
            avaterControl = other.GetComponent();
            avaterControl.canLadder = false;
            avaterControl.isOnLadder = false;
            Physics2D.IgnoreCollision(platform, other, false);
            //Debug.Log("    canLadder = false");
        }//

    }//OnTriggerEnter
...

 

 

 

 

参考资料:

1.Physics2D.IgnoreCollision

2.Unity2D入门5 爬梯子

3.

 

 

你可能感兴趣的:(Unity)