Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Taran0 · Nov 24, 2010 at 11:44 AM · switchflash

12 models appearing according to 4 variables, 2 switches - programming logic help

Im a novice programmer and just need some help on how to go about programming this task as i am doing it as a learning experience to improve my programming skills.

I have 12 versions of a model , each of which need to appear when the relevant settings are set.

the variables are 4 values, and then two on/off switches, of which only one can be on at any time, which creates 12 states in total. only one switch can be on but both can be off.

the possible settings are as follows:

variable - switch1 - switch2
1 - off - off
1 - on - off
1 - off - on
2 - off - off
2 - on - off
2 - off - on
3 - off - off
3 - on - off
3 - off - on
4 - off - off
4 - on - off
4 - off - on

I hope this makes sense, the way I would have done it in flash is to have 4 radiobuttons, and then two checkboxes and the update function would check the states of the checkboxes and then display the coresponding image (alpha) and hide the others.

alt text

what would be the best way to put this logic into practise in unity3 using JavaScript so that whenever a value is changed I can run the relevant renderer.enabled functions to show and hide the 11 models. I have already created the 11 models but cant figure out how to get the logic working right. I have tried to use 4 buttons and two toggles.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Taran0 · Dec 06, 2010 at 12:24 PM

Manged to work this one out with a bit of help from forums and unity answers. I used the toolbar row of buttons so that the 4 values could be selected , then just added two toggles and then used an if(GUI.changed) to update the state of the scene with multiple if statements.

to make sure only one toggle could be selected i created two functions that were called by the toggles to make sure the other toggle got switched off.

http://img143.imageshack.us/img143/4905/variables.jpg

not sure if this was the best way to go about it, but im a beginner programmer so was quite pleased with myself.

var toggleBrie = false; var toggleVert = false; var box1 : GameObject; var box2 : GameObject; var box3 : GameObject; var box4 : GameObject; var box5 : GameObject; var box6 : GameObject; var box7 : GameObject; var box8 : GameObject; var box9 : GameObject; var box10 : GameObject; var box11: GameObject; var box12: GameObject;

var toolbarInt = 0; var toolbarStrings : String[] = ["0.19", "0.29", "0.4", "0.64"];

function Start(){ box1.SetActiveRecursively(true); box2.SetActiveRecursively(false); box3.SetActiveRecursively(false); box4.SetActiveRecursively(false); box5.SetActiveRecursively(false); box6.SetActiveRecursively(false); box7.SetActiveRecursively(false); box8.SetActiveRecursively(false); box9.SetActiveRecursively(false); box10.SetActiveRecursively(false); box11.SetActiveRecursively(false); box12.SetActiveRecursively(false); }

function OnGUI () { GUI.skin = mySkin;

 GUI.BeginGroup (Rect (Screen.width - Screen.width + 20, Screen.height - Screen.height + 20, 300, 300));
 GUI.Label (Rect (20, 20, 100, 30), "G-Value");

 toolbarInt = GUI.Toolbar (Rect (20, 50, 250, 30), toolbarInt, toolbarStrings);
 GUI.EndGroup ();

     GUI.BeginGroup (Rect (Screen.width - Screen.width + 20, Screen.height - Screen.height + 80 , 400, 400));
 GUI.Label (Rect (40, 48, 200, 30), "Horizontal Shading");
 //toggleBrie = GUI.Toggle (Rect (25, 70, 50, 30), toggleBrie, "Value1");
 SetBrie (GUI.Toggle (Rect (20, 50, 100, 30),toggleBrie, ""));

 GUI.EndGroup ();


 GUI.BeginGroup (Rect (Screen.width - Screen.width + 20, Screen.height - Screen.height + 125 , 400, 400));
 GUI.Label (Rect (40, 48, 200, 30), "Vertical Shading");
 //toggleVert = GUI.Toggle (Rect (25, 70, 50, 30), toggleVert, "Value1");
 SetVert (GUI.Toggle (Rect (20, 50, 50, 30), toggleVert, ""));
 GUI.EndGroup ();

 GUI.Box (Rect (Screen.width - 115,40, 75, 85), logo);
 GUI.Label (Rect (Screen.width - 210, Screen.height - 60, 300, 30), texter);

 if(GUI.changed){
         if (toolbarInt == 0){
             box1.SetActiveRecursively(true);
             box2.SetActiveRecursively(false);
             box3.SetActiveRecursively(false);
             box4.SetActiveRecursively(false);
             box5.SetActiveRecursively(false);
             box6.SetActiveRecursively(false);
             box7.SetActiveRecursively(false);
             box8.SetActiveRecursively(false);
             box9.SetActiveRecursively(false);
             box10.SetActiveRecursively(false);
             box11.SetActiveRecursively(false);
             box12.SetActiveRecursively(false);
         }

         if (toolbarInt == 0 & toggleBrie == true){
             box1.SetActiveRecursively(false);
             box2.SetActiveRecursively(true);
             box3.SetActiveRecursively(false);
             box4.SetActiveRecursively(false);
             box5.SetActiveRecursively(false);
             box6.SetActiveRecursively(false);
             box7.SetActiveRecursively(false);
             box8.SetActiveRecursively(false);
             box9.SetActiveRecursively(false);
             box10.SetActiveRecursively(false);
             box11.SetActiveRecursively(false);
             box12.SetActiveRecursively(false);
         }

         if (toolbarInt == 0 & toggleVert == true){
             box1.SetActiveRecursively(false);
             box2.SetActiveRecursively(false);
             box3.SetActiveRecursively(true);
             box4.SetActiveRecursively(false);
             box5.SetActiveRecursively(false);
             box6.SetActiveRecursively(false);
             box7.SetActiveRecursively(false);
             box8.SetActiveRecursively(false);
             box9.SetActiveRecursively(false);
             box10.SetActiveRecursively(false);
             box11.SetActiveRecursively(false);
             box12.SetActiveRecursively(false);
         }

         if (toolbarInt == 1){
             box1.SetActiveRecursively(false);
             box2.SetActiveRecursively(false);
             box3.SetActiveRecursively(false);
             box4.SetActiveRecursively(true);
             box5.SetActiveRecursively(false);
             box6.SetActiveRecursively(false);
             box7.SetActiveRecursively(false);
             box8.SetActiveRecursively(false);
             box9.SetActiveRecursively(false);
             box10.SetActiveRecursively(false);
             box11.SetActiveRecursively(false);
             box12.SetActiveRecursively(false);
         }

         if (toolbarInt == 1 & toggleBrie == true){
             box1.SetActiveRecursively(false);
             box2.SetActiveRecursively(false);
             box3.SetActiveRecursively(false);
             box4.SetActiveRecursively(false);
             box5.SetActiveRecursively(true);
             box6.SetActiveRecursively(false);
             box7.SetActiveRecursively(false);
             box8.SetActiveRecursively(false);
             box9.SetActiveRecursively(false);
             box10.SetActiveRecursively(false);
             box11.SetActiveRecursively(false);
             box12.SetActiveRecursively(false);
         }

         if (toolbarInt == 1 & toggleVert == true){
             box1.SetActiveRecursively(false);
             box2.SetActiveRecursively(false);
             box3.SetActiveRecursively(false);
             box4.SetActiveRecursively(false);
             box5.SetActiveRecursively(false);
             box6.SetActiveRecursively(true);
             box7.SetActiveRecursively(false);
             box8.SetActiveRecursively(false);
             box9.SetActiveRecursively(false);
             box10.SetActiveRecursively(false);
             box11.SetActiveRecursively(false);
             box12.SetActiveRecursively(false);
         }

         if (toolbarInt == 2){
             box1.SetActiveRecursively(false);
             box2.SetActiveRecursively(false);
             box3.SetActiveRecursively(false);
             box4.SetActiveRecursively(false);
             box5.SetActiveRecursively(false);
             box6.SetActiveRecursively(false);
             box7.SetActiveRecursively(true);
             box8.SetActiveRecursively(false);
             box9.SetActiveRecursively(false);
             box10.SetActiveRecursively(false);
             box11.SetActiveRecursively(false);
             box12.SetActiveRecursively(false);
         }

         if (toolbarInt == 2 & toggleBrie == true){
             box1.SetActiveRecursively(false);
             box2.SetActiveRecursively(false);
             box3.SetActiveRecursively(false);
             box4.SetActiveRecursively(false);
             box5.SetActiveRecursively(false);
             box6.SetActiveRecursively(false);
             box7.SetActiveRecursively(false);
             box8.SetActiveRecursively(true);
             box9.SetActiveRecursively(false);
             box10.SetActiveRecursively(false);
             box11.SetActiveRecursively(false);
             box12.SetActiveRecursively(false);
         }

             if (toolbarInt == 2 & toggleVert == true){
             box1.SetActiveRecursively(false);
             box2.SetActiveRecursively(false);
             box3.SetActiveRecursively(false);
             box4.SetActiveRecursively(false);
             box5.SetActiveRecursively(false);
             box6.SetActiveRecursively(false);
             box7.SetActiveRecursively(false);
             box8.SetActiveRecursively(false);
             box9.SetActiveRecursively(true);
             box10.SetActiveRecursively(false);
             box11.SetActiveRecursively(false);
             box12.SetActiveRecursively(false);
         }

         if (toolbarInt == 3){
             box1.SetActiveRecursively(false);
             box1.SetActiveRecursively(false);
             box2.SetActiveRecursively(false);
             box3.SetActiveRecursively(false);
             box4.SetActiveRecursively(false);
             box5.SetActiveRecursively(false);
             box6.SetActiveRecursively(false);
             box7.SetActiveRecursively(false);
             box8.SetActiveRecursively(false);
             box9.SetActiveRecursively(false);
             box10.SetActiveRecursively(true);
             box11.SetActiveRecursively(false);
             box12.SetActiveRecursively(false);
         }

         if (toolbarInt == 3 & toggleBrie == true){
             box1.SetActiveRecursively(false);
             box2.SetActiveRecursively(false);
             box3.SetActiveRecursively(false);
             box4.SetActiveRecursively(false);
             box5.SetActiveRecursively(false);
             box6.SetActiveRecursively(false);
             box7.SetActiveRecursively(false);
             box8.SetActiveRecursively(false);
             box9.SetActiveRecursively(false);
             box10.SetActiveRecursively(false);
             box11.SetActiveRecursively(true);
             box12.SetActiveRecursively(false);
         }

         if (toolbarInt == 3 & toggleVert == true){
             box1.SetActiveRecursively(false);
             box2.SetActiveRecursively(false);
             box3.SetActiveRecursively(false);
             box4.SetActiveRecursively(false);
             box5.SetActiveRecursively(false);
             box6.SetActiveRecursively(false);
             box7.SetActiveRecursively(false);
             box8.SetActiveRecursively(false);
             box9.SetActiveRecursively(false);
             box10.SetActiveRecursively(false);
             box11.SetActiveRecursively(false);
             box12.SetActiveRecursively(true);
         }
     }

}

function Update () { // Debug.Log(toolbarInt);

 if (Input.GetKeyDown(KeyCode.Escape)) {
     Application.Quit();
     }

}

function SetVert (state : boolean) { if (state) { SetBrie (false); } toggleVert = state; }

function SetBrie (state : boolean) { if (state) { SetVert (false); } toggleBrie = state; }

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

No one has followed this question yet.

Related Questions

Switch between characters and follow? 3 Answers

Switching abilitys too fast 0 Answers

Switch Case for Basic AI.... 1 Answer

3rd Person to First Person Camera 0 Answers

Gravity switch not working 0 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