• 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
Question by Jesus_Freak · Dec 27, 2010 at 06:41 PM · switchjavascript-specificswitch-case

Switch cases malfunction?

In my script(below) the 2 vars alpha and pageNumber have a system where they change based on which button you click. But now it doesn't change anymore- they used to go up and down but now they stay at 1.

Can you take a look at my script and help me figure out what needs to be changed to make those 2 vars change?

(for some reason, my whole script doesn't show on safari)

thanks for any help!

"Tutorial" Script:

var firstMessage : String; var secondMessage : String; var thirdMessage : String; var fourthMessage : String; var fifthMessage : String; var sixthMessage : String; var seventhMessage : String; var buttonWidth : int; var buttonHeight : int; var X : int; var Y : int; var alpha : int; var beta : int; var Rect1 : Rect; var Rect2 : Rect; var pagePosition : Rect; var nextRect : Rect; var backRect : Rect; var windowRect : Rect = Rect((Screen.width / 2) - (buttonWidth / 2), (Screen.height / 2) - (buttonHeight / 2), buttonWidth, buttonHeight); var windowRect2 : Rect = Rect((Screen.width / 2) - (buttonWidth / 2), (Screen.height / 2) - (buttonHeight / 2), buttonWidth, buttonHeight); private var showGUI : boolean = false; private var firstTime : boolean = true; private var ShowDefault : boolean = true; private var ShowSecond : boolean = false; private var ShowThird : boolean = false; private var ShowFourth : boolean = false; private var ShowFifth : boolean = false; private var ShowSixth : boolean = false; private var ShowSeventh : boolean = false; private var ShowNext : boolean = false; private var msgToDisplay : String; private var pageNumber : int; private var pageToDisplay : int;

function Awake() { pageNumber = 0; alpha = 1; showGUI = false; FMoveAround.Takeinput = false; msgToDisplay = firstMessage; firstTime = true; } function Update() { switch(pageNumber) { case -1: pageNumber = 0; break; case 0: pageToDisplay = 1; break; case 1: pageToDisplay = 2; break; case 2: pageToDisplay = 3; break; case 3: pageToDisplay = 4; break; case 4: pageToDisplay = 5; break; case 5: pageToDisplay = 6; break; case 6: pageToDisplay = 7; break; case 7: pageNumber = 6; break; } switch(alpha) { case 0: alpha = 1; break; case 1: msgToDisplay = firstMessage; FMoveAround.Takeinput = false; break; case 2: msgToDisplay = secondMessage; FMoveAround.Takeinput = true; break; case 3: msgToDisplay = thirdMessage; FMoveAround.Takeinput = true; break; case 4: msgToDisplay = fourthMessage; FMoveAround.Takeinput = true; break; case 5: msgToDisplay = fifthMessage; FMoveAround.Takeinput = true; break; case 6: msgToDisplay = sixthMessage; FMoveAround.Takeinput = true; break; case 7: msgToDisplay = seventhMessage; FMoveAround.Takeinput = false; break; case 8: showGUI = true; FMoveAround.Takeinput = false; break; } }

function DoMyWindow (windowID : int) { GUI.skin.label.wordWrap = true; GUI.Label(pagePosition, "Page " + pageToDisplay); GUI.Label(Rect2, msgToDisplay); GUI.Label(Rect1, "Date, Time: " + System.DateTime.Now); if(GUI.Button(nextRect, "Next")) { alpha++; pageNumber++; } if(GUI.Button(backRect, "Back")) { alpha--; pageNumber--; } GUI.DragWindow (); } var Rect3 : Rect; var Rect4 : Rect; function DoMyWindowQuit(windowID : int) { GUI.skin.button.wordWrap = true; if(GUI.Button(Rect3, "Level 1-->")) { Application.LoadLevel("Level1"); } if(GUI.Button(Rect4, "<--Back")) { alpha = 7; showGUI = false; } }

function OnGUI() { if(!showGUI) { windowRect = GUI.Window(0, windowRect, DoMyWindow, "Tutorial 1"); } if(showGUI) { windowRect2 = GUI.Window(1, windowRect2, DoMyWindowQuit, "Finished learning from the tutorial?"); } }

Comment

People who like this

0 Show 4
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 Jesus_Freak · Dec 28, 2010 at 09:32 PM 0
Share

theres no other script changing the value of alpha or page number, they can be different than one, i changed it in edit mode and playmode, but it always starts on 1 which is good but it never changes on its own (when you press the buttons) which is bad; this script did work before but now it doesn't for some reason unkown to me.

avatar image Eric5h5 · Dec 28, 2010 at 10:01 PM 0
Share

Rewrite this to use arrays instead of a ton of separate variables, right now it's way too long.

avatar image Jesus_Freak · Dec 29, 2010 at 08:00 PM 0
Share

ok, i'm working on converting the string to an array, but im confused about arrays, i've used the "for(var in array)" technique but i don't truly know about arrays, could you explain arrays and how to increase the value of an array? i'm going to ask a new question explaining this... i know virtually nothing about arrays.

avatar image JesusChristChangedMe · Jan 03, 2011 at 01:53 AM 0
Share

It's not all showing up on your iPod I think what you mean by safari. Use a computer, it will show the entire script.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Problem with my weapons switch statement C# 3 Answers

Why would my switch's case be correct but the output is not? 2 Answers

Why does my Switch statement only go through one case correctly? 1 Answer

Switch statement not running on every frame 1 Answer

I would like some help refactoring my code, I am working with switch cases concering the delivery of food items in my game 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