Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by velv · May 07, 2012 at 11:58 AM · gameobjecttriangle

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.

alt text

Any ideas of how can i generate this type of roof? Thanks in advance.

photo.jpg (495.0 kB)
Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image velv · May 07, 2012 at 02:18 PM 0
Share

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.

avatar image Bunny83 · May 07, 2012 at 02:37 PM 0
Share

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.

avatar image velv · May 07, 2012 at 04:32 PM 0
Share

Can you give an example? Thanks

(Sorry for this comment thing, but i had an issue loading the page)

avatar image Bunny83 · May 08, 2012 at 02:55 AM 0
Share

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.

avatar image velv · May 08, 2012 at 09:47 AM 0
Share

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?  

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image velv · May 07, 2012 at 02:12 PM 0
Share

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?

avatar image SrujanBarai · May 29, 2015 at 02:13 PM 0
Share

@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.

avatar image
0

Answer by Cornelis-de-Jager · Apr 24, 2019 at 12:55 AM

There are many solutions to this.


  1. Draw it using Meshes and Verticies (Hardest Method Here but gives you power to customize better) Tutorial - https://www.youtube.com/watch?v=IYMQ2ErFz0s

  2. 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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges