Answer the question
In order to leave comments, you need to log in
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 = ....;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question