Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by ajrosenbach · Jan 26, 2019 at 10:00 PM · 3d modeltriangles

Is there a premade triangle asset?

Hi! I'm new to Unity and my project is to make a prefab out of primitives. So, I decided to try to make a house, I was able to do it mostly with cubes of varying sizes, but when it comes to the roof, if I want the triangular shaped kind I need a triangle for the front and back of the roof. I read that you need a modeling program to make it. I am not a fan of that situation since I have never used one, is there really no way to create a triangle in Unity without modeling software? It just seems so strange they give you Cubes and Spheres and even Capsules but NOT Triangles, doesn't? Even more strange is that the Asset Store seems to be devoid of anything triangles when I tried looking for one.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
5

Answer by BastianUrbach · Jan 27, 2019 at 11:23 AM

There is no builtin triangle primitive. Luckily the Unity Editor is easy to extend. Put this script somewhere in your project folder and a new "Triangle" button should pop up in the GameObject/3D Object menu.

 #if UNITY_EDITOR
 using UnityEngine;
 using UnityEditor;
 #endif
 
 public class TrianglePrimitive {
     #if UNITY_EDITOR
     private static Mesh CreateMesh() {
         Vector3[] vertices = {
             new Vector3(-0.5f, -0.5f, 0),
             new Vector3(0.5f, -0.5f, 0),
             new Vector3(0f, 0.5f, 0)
         };
 
         Vector2[] uv = {
             new Vector2(0, 0),
             new Vector2(1, 0),
             new Vector2(0.5f, 1)
         };
 
         int[] triangles = { 0, 1, 2 };
 
         var mesh = new Mesh();
         mesh.vertices = vertices;
         mesh.uv = uv;
         mesh.triangles = triangles;
         mesh.RecalculateBounds();
         mesh.RecalculateNormals();
         mesh.RecalculateTangents();
         return mesh;
     }
 
     private static GameObject CreateObject() {
         var obj = new GameObject("Triangle");
         var mesh = CreateMesh();
         var filter = obj.AddComponent<MeshFilter>();
         var renderer = obj.AddComponent<MeshRenderer>();
         var collider = obj.AddComponent<MeshCollider>();
 
         filter.sharedMesh = mesh;
         collider.sharedMesh = mesh;
         renderer.sharedMaterial = AssetDatabase.GetBuiltinExtraResource<Material>("Default-Material.mat");
 
         return obj;
     }
 
     [MenuItem("GameObject/3D Object/Triangle", false, 0)]
     public static void Create() {
         CreateObject();
     }
     #endif
 }
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 apoorvjaiswal56 · Sep 10, 2021 at 04:21 PM 0
Share

which file extension to save? @BastianUrbach

avatar image BastianUrbach apoorvjaiswal56 · Sep 10, 2021 at 04:32 PM 0
Share

.cs

(Ignore this line, it's only there because comments are required to have at least ten characters)

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

100 People are following this question.

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

Related Questions

Realtime mesh triangles do not appear depending on camera angle 1 Answer

What is a good number of tris to shoot for in my game? 1 Answer

How to control the triangles of a model in scripts? 1 Answer

Organize Triangles of a Subdivided Quad? 1 Answer

Hexagon mesh subdivided into triangles 1 Answer


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