Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Jul 20, 2016 at 07:34 PM by Jessespike for the following reason:

Question is off-topic or not relevant.

avatar image
2
Question by 686InSomNia686 · Jul 18, 2016 at 10:14 AM · c#script.axisopengllines

[Tutorial] Draw Axis like a 3D modeler (C#)

Hi everyone, I didn't find any post about it, so I share my little script (based on the Unity tutorial) to draw the XYZ axis.

 using UnityEngine;
 using System.Collections;
 
 public class AxisXYZ : MonoBehaviour
 {    
     static Material lineMaterial;
     static void CreateLineMaterial()
     {
         if (!lineMaterial)
         {
             // Unity has a built-in shader that is useful for drawing
             // simple colored things.
             Shader shader = Shader.Find("Hidden/Internal-Colored");
             lineMaterial = new Material(shader);
             lineMaterial.hideFlags = HideFlags.HideAndDontSave;
             // Turn on alpha blending
             lineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
             lineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
             // Turn backface culling off
             lineMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
             // Turn off depth writes
             lineMaterial.SetInt("_ZWrite", 0);
         }
     }
 
     // Will be called after all regular rendering is done
     public void OnRenderObject()
     {
         CreateLineMaterial();
         // Apply the line material
         lineMaterial.SetPass(0);
 
         GL.PushMatrix();
         // Set transformation matrix for drawing to
         // match our transform
         GL.MultMatrix(transform.localToWorldMatrix);
 
         // Draw lines
         GL.Begin(GL.LINES);
         //Draw X axis
         GL.Color(Color.red);
         GL.Vertex3(0, 0, 0);
         GL.Vertex3(10.0f, 0.0f, 0.0f);
         //Draw Y axis
         GL.Color(Color.green);
         GL.Vertex3(0, 0, 0);
         GL.Vertex3(0.0f, 10.0f, 0.0f);
         //Draw Z axis
         GL.Color(Color.blue);
         GL.Vertex3(0, 0, 0);
         GL.Vertex3(0.0f, 0.0f, 10.0f);
         GL.End();
         GL.PopMatrix();
     }
 }

You just need to attach that script to a GameObject placed in the Center of your scene and it's DONE! A way to improve it, it will be to change the size of the lines depending of the size of your object. PEACE! Clément

EDIT : I have improved my system by putting the axis on the right bottom of my screen like every 3D modeler (Unity, 3D's max...). To succeed that, create an empty GameObject (GO). Place it far away from the scene (1000.0f,1000.0f,1000.0f). Inside that GO there is :

  • A GO with the script above and create an "Axis" layer in Unity Editor.

  • A Camera

That camera has a small viewport (W 0.25, H 0.25) and it is placed on the bottom right of the screen (X 0.75, Y 0.0)

The Culling mask is only on the layer "Axis" and the Clear FLags is "Depth only".

Place an "Orbital mouse script" on the Main Camera and on "CameraAxis". You can add in this script, like me, a boolean which define if the orbital script is allowed to zoom or not. For the "Main Camera" the scroll is enable. For the "CameraAxis", it's more convenient if the scroll is not enable.

You can see here all my setup : alt text

axis-draw.png (121.2 kB)
Comment
Comments Locked · Show 1
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 Jessespike · Jul 20, 2016 at 07:33 PM 0
Share

Tutorials are appreciated, but posting them on Unity Answers as a question seems inappropriate. The forum would probably be more suitable.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

194 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 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

How do I make somthing happen when the Player reaches a certain x, y, z position? 0 Answers

Can someone please help me find out what wrong with my code. 0 Answers

How to make an enemy 2d chasing player? 1 Answer

I can't load play mode 2 Answers

How to set a bool from a script equal to another bool from another script? 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