Z
Z
Zefirot2021-10-18 12:51:19
Unity
Zefirot, 2021-10-18 12:51:19

How to adjust borders with collider?

I have a prefab (BoxCollider2D) in it 4 prefabs (4 rectangular pictures of the border, along the edge of the collider), I want to change their position by changing the borders of the collider, that is, attach the pictures to the borders of the collider

public class Border : MonoBehaviour{
    public GameObject BRight; // 25, 0
    public GameObject BBottom; // 0, -25
    public GameObject BTop; // 0, 25
    public GameObject BLeft; // -25, 0
    public BoxCollider2D BorderBound;
    public void UpdateBorder(){
        float BSizeX = BorderBound.size.x;
        float BSizeY = BorderBound.size.y;
        float BOffsetX = BorderBound.offset.x;
        float BOffsetY = BorderBound.offset.y;
        BRight.gameObject.transform.position = new Vector3(11f + BSizeX, 0f, 0f);
        //BBottom.gameObject.transform.position = ....;
        BTop.gameObject.transform.position = new Vector3(0f, 11f + BSizeY, 0f);
        //BLeft.gameObject.transform.position = ....;
        }
    }

at the moment it turns out to bind to the right and top side, but when I bind the rest, carousels begin, I suppose you need to take offset into account, but I still can’t figure out how it should be correct, tell me how it should be?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question