C # Unity Gizmos visual aids

Source: Internet
Author: User

All gizmo drawing needs to be done in the script's Ondrawgizmos or ondrawgizmosselected function.

Ondrawgizmos is called at each frame. All the gizmos that are rendered in Ondrawgizmos are visible.

Ondrawgizmosselected is called only if the object attached to the script is selected.


    1. Gizmos.drawline

Draw a line from obj1 to Obj2.

Using unityengine;using System.collections;public class Drawlinetext:monobehaviour {public Gameobject obj1;        Public Gameobject Obj2;        void Ondrawgizmos () {gizmos.color = Color.green;    Gizmos.drawline (Obj1.transform.position, obj2.transform.position); }}


2.gizmos.drawray

Draw a 10-length ray from obj

Using unityengine;using System.collections;public class Drawraytext:monobehaviour {public Gameobject obj;        void Ondrawgizmos () {gizmos.color = Color.gray;  Gizmos.drawray (obj.transform.position, Vector3.up * 10); 10 is the length}}


3.gizmos.drawcube

Draw A (1,1,1)-sized cube at (0,1,0)

Using unityengine;using System.collections;public class Drawcubetext:monobehaviour {void Ondrawgizmos () {        Gizmos.color = color.red;    Gizmos.drawcube (Vector3.up, Vector3.one); }}


4.gizmos.drawicon

Generate an icon named 002imgzlzy6mro7r94ka2&690.jpg at (0,0,0), which will be placed in the Gizmos folder under assets.

Using unityengine;using System.collections;public class Drawicontext:monobehaviour {void Ondrawgizmos () {    Gizmos.drawicon (Vector3.zero, "002imgzlzy6mro7r94ka2&690.jpg"); }}


This article is from the "Sea Know Sleepless" blog, please be sure to keep this source http://745559847.blog.51cto.com/11658719/1891989

C # Unity Gizmos visual aids

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.