- Home /
How to make a triangle shaped roof?
hi guys, i'm newbie to Unity 3D. I work on a project building procedurally buildings. My problem is: I stuck on how to make a roof Object by scripting and attach it to a gameObject. The model of my roof is like this picture below.
Any ideas of how can i generate this type of roof? Thanks in advance.
I want to build this procedurally by using a script. Another idea: I can see a triangle by using this script when i put it into a cube object. I can scale the X and Y points but not the Z point so i can give it width.
Another question is, do i need to put this script into a specific object (like a Cube)? Simply, I want to create a single triangle and play with its XYZ coordinates, so i can attach it to my first floor cube (actually i create a Cube GameObject to be my first floor).
If i'm still unclear to what i want to do, please tell me. Thanks in advance.
Don't attach it to a cube. If you create a cube-gameobject it already has a meshfilter and a mesh renderer attached. Just attach it to an empty gameobject.
Btw: Don't post such things as answer. Use comments ins$$anonymous$$d or edit your question if you want to add more details.
Can you give an example? Thanks
(Sorry for this comment thing, but i had an issue loading the page)
What do you mean by example? You have the script, right? Do you need an example how you create an empty GameObject?
In Unity the main menu at the top --> GameObject --> Create Empty
It's the first thing in this menu.
ok by now. How can i change the Z point of this triangle? It doesn't allow me to give it width. 1) In case of a GameObject i would type: obj.transform.localScale.z = 10; Now, in case of a mesh what should i do to access triangle's Z point?
2) function Start () { gameObject.AddComponent("$$anonymous$$eshFilter"); gameObject.AddComponent("$$anonymous$$eshRenderer"); var mesh : $$anonymous$$esh = GetComponent($$anonymous$$eshFilter).mesh;
mesh.Clear();
mesh.vertices = [Vector3(0,0,0), Vector3(0,1,0), Vector3(1, 1, 0)];
mesh.uv = [Vector2 (0, 0), Vector2 (0, 1), Vector2 (1, 1)];
mesh.triangles = [0, 1, 2];
new GameObject ("triangle", typeof($$anonymous$$eshRenderer), typeof(Text$$anonymous$$esh)); //is this the right way to create an empty object and put the mesh in it?
Answer by Bunny83 · May 07, 2012 at 12:01 PM
This is one of the most primitive volumes you could create. Do you even know how to create a Mesh procedurally? Do you ask for an out-of-the-box solution? What could someone answer to such a question except a script that does what you want?
Take a look at the Mesh class.
I tried to use this script. It didn't help me that much. I put this script into a Cube Object so i can see the triangle shape. Well, i can scale the X and Y points but i can't give it a width (Z point). I just want to change the XYZ coordinates to do a similar shape like the above picture, and then attach it to my first floor (also created procedurally). Am i doing a mistake by putting the script into a Cube Object?
@velv: You need to use right terms in comments. What you want to change is the depth of the triangle, not the width. The scrip will give only a 2D triangle. Changing Z axis will just translate it from one place to another. You cant give it depth. To give depth you'll have to write a new scrip where you have to create two triangle (parallel to each other) and fill the space in between.
Answer by Cornelis-de-Jager · Apr 24, 2019 at 12:55 AM
There are many solutions to this.
Draw it using Meshes and Verticies (Hardest Method Here but gives you power to customize better) Tutorial - https://www.youtube.com/watch?v=IYMQ2ErFz0s
Create a Prefab and instantiate it then resize at the correct location.
Side Note - What you are asking is on of the most basic of basics. The people here are nice enough to answer smaller questions like this - but if you really want to make a game and be good at it. You realy need to put more effort into improving yourself. I HIGHLY recommend that you do some tutorials on the types of games you want to make, then try to make your own version of it. It is the best way to learn.
Your answer
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Cannot rotate a triangle shape! 1 Answer
scaling plane gameobject to fit orthographic view iphone unity3d 0 Answers
Continually Updating position of Instantiated Object (to Mouse Pointer) 0 Answers
DontDestory gameobject doesn't work on button click after a new scene loads 2 Answers