Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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
0
Question by DustyScreen · May 31, 2013 at 10:15 PM · 3dgraphicsgenerated

Generating a triangle from 3 points

I try to generate a one colored triangle from 3 points, but I'm stuck...

So I want to make an empty game object with a script (preferably C#), that does this. The script uses 3 3d coordinates and a color (lets say blue) to generate it.

Can anyone help?

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

5 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by s_guy · May 31, 2013 at 11:50 PM

From the official docs on meshes

 // Builds a mesh containing a single triangle with uv's.
 function Start () {
     gameObject.AddComponent("MeshFilter");
     gameObject.AddComponent("MeshRenderer");
     var mesh : Mesh = GetComponent(MeshFilter).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];
 }

...and then the official docs on materials has an example for setting material color

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
avatar image
1

Answer by aldonaletto · May 31, 2013 at 10:56 PM

If you want to play in the OpenGL style, use the GL class to draw the triangle - there's a very useful example in this topic.

But if you want to create a game object with a simple triangular mesh, take a look at the mesh topic in the Unity manual, or at the Mesh class in the docs - both have useful examples, and the later allows selection of C# language.

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
avatar image
1

Answer by huse · Nov 17, 2019 at 04:24 PM

Here you can learn step by step how to draw a triangle just by code (Turn on English subtitles) https://www.youtube.com/watch?v=ThWyvoqWjhE&list=PLp2zpxnnEFuemzgoUFYGkKQWwygDFXiIt![alt text][1]

[1]: /storage/temp/148854-triangle-unity.png


triangle-unity.png (142.4 kB)
Comment
Add comment · Show 1 · 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 StarArcher · Apr 25 at 12:31 PM 0
Share

This was exactly what I needed. Thank you.

avatar image
0

Answer by ExpiredIndexCard · May 31, 2013 at 10:32 PM

Make a triangle I'm blender then export to unity and turn off the mesh renderer. Simply solution

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
avatar image
0

Answer by Xathereal · May 31, 2013 at 10:44 PM

Well, I not so recommended way, but a way you can generate a triangle is using calls to OpenGL directly:

 GL.Begin( GL.TRIANGLES);
 GL.Color( Color(1,1,1,1) );
 GL.Vertex3( 0, 0, 1 );
 GL.Vertex3( 1, 0, 1 );
 GL.Vertex3( 0, 1, 1 );
 GL.End();

Something to that effect, do some googling and you will find plenty of resources on OpenGL.

But, to make a GameObject that will rotate, scale and do everything you want, and have a triangle shape, you would be best off making the object in something like Blender.

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

18 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

Related Questions

Tutorial on adding texture and images to 3d objects? 2 Answers

Raymarching Bug - Rendering 3D texture in real-time 0 Answers

How to create Vectrex(Vector) look in games ? 2 Answers

Looking for a simple way to Add an Image or text to a 3d Model 1 Answer

3D models bugs with Unity 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