Monitor Gameobject Click events #你好Unity3D #hierarchy View

Source: Internet
Author: User
Tags call back

I found another good way today.

12345678910 [initializeonloadmethod] static void Start () { Selection. SelectionChanged = delegate { Debug. Log(Selection. Activeobject. Name); }; }

A few days ago a friend asked me how to listen to the Sceneview and hierarchy view Select an event of a gameobject, today I have time to do research.

Do you know the following two agent events? You can actually do it, but it's not perfect. Because every frame will be called to make a judgment
Editorapplication.hierarchywindowitemongui
Editorapplication.update

I think the best way, or when I choose a gameobject, by unity callback to give me an event. So I found an imperfect solution. Add the following code to the Gameobject script where you need to listen for clicks. Ondrawgizmosselected is the chosen callback. But it may call back multiple times, so make a judgment to make sure it executes only once.

1234567891011 #if unity_editor bool selected = false; void ondrawgizmosselected()     { if (! Selected)         { selected = true; Debug. Log(gameobject. Name);         }    }#endif

If you want to deal with it in one place, just get it out of the way. OK This article is a pseudo-proposition, if you have a better way to welcome the following message to me, thank you!

    • This article fixed link: http://www.xuanyusong.com/archives/3773
    • Reprint Please specify: Rain pine Momo November 29, 2015 Yu Yussong Momo Program Research Institute published

Monitor Gameobject Click events #你好Unity3D #hierarchy View

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.