Esempio n. 1
0
        /* Functions */

        private void Awake()
        {
            mBoxCollider2d  = this.GetComponent <BoxCollider2D>();
            mRigidbody2d    = this.GetComponent <Rigidbody2D>();
            mSpriteRenderer = this.GetComponent <SpriteRenderer>();

            // get the box info.
            mBoxInfo = JCS_Physics.GetColliderInfo(mBoxCollider2d);

            // set to never sleep
            mRigidbody2d.sleepMode = RigidbodySleepMode2D.NeverSleep;

            mBottomColliders = new List <Collider2D>();
            mTopColliders    = new List <Collider2D>();
            mRightColliders  = new List <Collider2D>();
            mLeftColliders   = new List <Collider2D>();
        }
Esempio n. 2
0
        /// <summary>
        /// Draw the collider, use for check last frame.
        /// </summary>
        /// <param name="collider"> Collider u want to draw. </param>
        /// <param name="col"> Color type. </param>
        /// <param name="origin">Provide the origin position. </param>
        public static void DrawCollider(BoxCollider2D collider, Color col, Vector3 origin)
        {
#if (UNITY_EDITOR)
            // get width and height information.
            Vector2 boxInfo = JCS_Physics.GetColliderInfo(collider);

            Vector3 pos = origin;

            Vector3 topLeft = new Vector3(
                pos.x - boxInfo.x / 2,
                pos.y + boxInfo.y / 2);
            Vector3 topRight = new Vector3(
                pos.x + boxInfo.x / 2,
                pos.y + boxInfo.y / 2);
            Vector3 botRight = new Vector3(
                pos.x + boxInfo.x / 2,
                pos.y - boxInfo.y / 2);
            Vector3 botLeft = new Vector3(
                pos.x - boxInfo.x / 2,
                pos.y - boxInfo.y / 2);

            DrawRect(topLeft, topRight, botRight, botLeft, col);
#endif
        }