Enum property + other Script Access

Source: Internet
Author: User

Use Enum Property

In the bom2 project, you must have a separate script to control mode switching. Other scarima determines which Enum to switch to based on this mode to enable some functions in this mode. At the beginning, I used the Inspector method to control the enum selected value in the enum script, and then created a public variable in the script to be judged to adapt to the enum value changes. Later I changed to using the enum method of the class.
 //  Modeselector. CS  Using  Unityengine;  Using  System. collections;  Public   Enum  Modeenum {assemblyview, tearview, profileview, lateral view}  Public   Class Modeselector: monobehaviour {  Private   Static   Int  Myvar;  Public   Static  Modeenum modeenumproperty {  Get { Return  (Modeenum) myvar ;}  Set {Myvar = ( Int  ) Value ;}} //  Use this for initialization          Void  Start () {modeenumproperty = Modeenum. assemblyview ;}  //  Update is called once per frame          Void  Update (){}  Void  Ongui (){  If (GUI. Button ( New Rect (screen. width/2 - 150 , 50 , 100 , 20 ), "  Tear apart  "  ) {Modeenumproperty = Modeenum. tearview ;}  If (GUI. Button ( New Rect (screen. width/ 2 +50 , 50 , 100 , 20 ), "  3D viewer  "  ) {Modeenumproperty = Modeenum. assemblyview ;}}} 
//Navigationcontrol. CSOngui (){...If(Modeselector. modeenumproperty =Modeenum. assemblyview ){//Something to do}...}

 

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.