Я пытаюсь динамически создавать невидимые стены вокруг экрана с помощью скрипта, и на данный момент мне удалось найти координаты нижнего левого, верхнего, верхнего и нижнего правого вектора Vector3.
Я написал этот метод для создания стены, но ориентация стены кажется неправильной:
Код: Выделить всё
void SpawnWall(string wallName, Vector3 startPosition, Vector3 endPosition, Vector3 center)
{
// Create & center the wall between the start and end positions
GameObject wall = new GameObject(wallName);
wall.transform.position = (startPosition + endPosition) / 2;
BoxCollider wallCollider = wall.AddComponent();
// Adjust the collider size and position
wallCollider.size = new Vector3((endPosition - startPosition).magnitude, wallHeight, wallThickness);
// Make the wall face towards the center
//Vector3 direction = Vector3.Cross(startPosition, endPosition);
wall.transform.LookAt(center);
walls.Add(wall);
}

The red, blue, green & pink lines on the screen are the boundaries I'm trying to create the invisible walls. These are the positions I'm testing with:
Код: Выделить всё
Vector3 bottomLeft = new Vector3(-13.80, 0.00, -6.82);
Vector3 topLeft = new Vector3(-17.52, 0.00, 13.02);
Vector3 topRight = new Vector3(14.43, 0.00, 9.41);
Vector3 bottomRight = new Vector3(6.38, 0.00, -9.10);
Источник: https://stackoverflow.com/questions/781 ... in-unity3d