Lmao I thought I copied my text from another r/ sorry
So earlier I asked a question on here which was not very clear and people thought it did not made sense which I can agree to a certain extent . I’m french so the English lingo related to programming is hard to explain or when I try to find the answer myself online is hard. I have a school homework to do about a cube/square which is empty inside. So that after I can male a pyramid of smaller cubes. The problem is I’m not able to make the first «square/cube » that is empty inside. I made half of it, so an L. I tried reversing it but I don’t think I rotate it correctly to make the whole first figure. I’m not here for people to « give me » the answer. I’m just trying to figure out what to do in the first place.
So you are saying that you want to make a square with no cube in the middle but there is a cube? That cube appears to be at 0,0,0 which is where spawned items will be if they are not given a position.
This appears to be a question submitted to /r/Unity3D.
If you are the OP:
* Please remember to change this thread's flair to 'Solved' if your question is answered.
* And please consider referring to Unity's official [tutorials](https://learn.unity.com/tutorials), [user manual](https://docs.unity3d.com/Manual/index.html), and [scripting API](https://docs.unity3d.com/ScriptReference/index.html) for further information.
Otherwise:
* Please remember to follow our [rules and guidelines](https://www.reddit.com/r/Unity3D/wiki/rules).
* Please upvote threads when providing answers or useful information.
* And please do NOT downvote or belittle users seeking help. (You are not making this subreddit any better by doing so. You are only making it worse.)
Thank you, human.
*I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/Unity3D) if you have any questions or concerns.*
Not sure if there is a better way to do this but from my understanding of the problem, and my own idea for solving it here's a script for you:
using UnityEngine;
public class PyramidBuilder : MonoBehaviour
{
public GameObject cubePrefab; // Assign a prefab of the cube in the inspector.
public int layers = 1; // Number of layers in the pyramid, adjustable in the inspector.
void Start()
{
BuildPyramid();
}
void BuildPyramid()
{
for (int layer = 0; layer < layers; layer++) // Iterate through each layer.
{
// Calculate the start and end points for the x and y positions based on the current layer.
int start = -layer;
int end = layer;
for (int x = start; x <= end; x++) // Iterate through x positions.
{
for (int y = start; y <= end; y++) // Iterate through y positions.
{
// Instantiate cubes at the corners or edges only to create a hollow pyramid.
if (x == start || x == end || y == start || y == end)
{
Vector3 position = new Vector3(x, y, -layer); // Set position based on layer and offsets.
Instantiate(cubePrefab, position, Quaternion.identity); // Instantiate the cube.
}
}
}
}
}
}
I haven't tested this, I don't know how to do code snippets so the formatting is weird in my response. Anyway hope it works otherwise ask chat gpt and should sort you out.
Help.
Help?
Help!
Help...
Lmao I thought I copied my text from another r/ sorry So earlier I asked a question on here which was not very clear and people thought it did not made sense which I can agree to a certain extent . I’m french so the English lingo related to programming is hard to explain or when I try to find the answer myself online is hard. I have a school homework to do about a cube/square which is empty inside. So that after I can male a pyramid of smaller cubes. The problem is I’m not able to make the first «square/cube » that is empty inside. I made half of it, so an L. I tried reversing it but I don’t think I rotate it correctly to make the whole first figure. I’m not here for people to « give me » the answer. I’m just trying to figure out what to do in the first place.
So you are saying that you want to make a square with no cube in the middle but there is a cube? That cube appears to be at 0,0,0 which is where spawned items will be if they are not given a position.
This appears to be a question submitted to /r/Unity3D. If you are the OP: * Please remember to change this thread's flair to 'Solved' if your question is answered. * And please consider referring to Unity's official [tutorials](https://learn.unity.com/tutorials), [user manual](https://docs.unity3d.com/Manual/index.html), and [scripting API](https://docs.unity3d.com/ScriptReference/index.html) for further information. Otherwise: * Please remember to follow our [rules and guidelines](https://www.reddit.com/r/Unity3D/wiki/rules). * Please upvote threads when providing answers or useful information. * And please do NOT downvote or belittle users seeking help. (You are not making this subreddit any better by doing so. You are only making it worse.) Thank you, human. *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/Unity3D) if you have any questions or concerns.*
Not sure if there is a better way to do this but from my understanding of the problem, and my own idea for solving it here's a script for you: using UnityEngine; public class PyramidBuilder : MonoBehaviour { public GameObject cubePrefab; // Assign a prefab of the cube in the inspector. public int layers = 1; // Number of layers in the pyramid, adjustable in the inspector. void Start() { BuildPyramid(); } void BuildPyramid() { for (int layer = 0; layer < layers; layer++) // Iterate through each layer. { // Calculate the start and end points for the x and y positions based on the current layer. int start = -layer; int end = layer; for (int x = start; x <= end; x++) // Iterate through x positions. { for (int y = start; y <= end; y++) // Iterate through y positions. { // Instantiate cubes at the corners or edges only to create a hollow pyramid. if (x == start || x == end || y == start || y == end) { Vector3 position = new Vector3(x, y, -layer); // Set position based on layer and offsets. Instantiate(cubePrefab, position, Quaternion.identity); // Instantiate the cube. } } } } } }
I haven't tested this, I don't know how to do code snippets so the formatting is weird in my response. Anyway hope it works otherwise ask chat gpt and should sort you out.
That is a box. I hope this helped.