Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 missypooh · Jul 18, 2011 at 03:47 PM · arraylistloadleveldontdestroyonload

combine words of different scenes in a list or array; have each word link to a page

Hello everyone. I would like to ask a few questions. Basically i am creating an educational puzzle game (form words).

My first question is that how do i combine all the words formed in each level into one scene? For example, player form 6 words in level1, form 8 words in level2 etc.. So i will have a scene called "Revision" that allow player to refresh their memory on what words they have form in each level. Refer to the image for more details. http://imageshack.us/photo/my-images/41/revisionk.png/

Second, whenever player finish level1, they will be proceed to level1Complete which will show them what words they have form in level1. Then i am intending to create a link that will direct them to an "explanation" page which will explain what the individual word mean? So how could i do about it??

Comment
Add comment · 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 missypooh · Jul 19, 2011 at 05:31 AM 0
Share

hi sister$$anonymous$$y, i will be more careful with my title of the question next time. Thank you for the feedback :)

avatar image almo · Jul 19, 2011 at 11:41 AM 1
Share

Title edited

avatar image missypooh · Jul 19, 2011 at 11:45 AM 0
Share

hello almo, thank you for editing the title for me. Sorry guys, i will be careful of it the next time and read properly all the rules.

THAN$$anonymous$$ YOU.

avatar image SisterKy · Jul 30, 2011 at 07:51 PM 0
Share

more detail on this question to be found here: http://answers.unity3d.com/questions/146501/how-to-link-words-from-different-scene.html Greetz, $$anonymous$$y.

3 Replies

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

Answer by SisterKy · Jul 21, 2011 at 03:09 PM

1 one GameObject 'Manager' with don't destroy on load and and one var level01Words : List; for each Level and a function FeedWord that takes level : int and word : String as Parameters. The Function then tests what level it got as input (you can do it with if-statements, but I'd rather search for switch/case). depending on level, add the word to the appropriate levelWords-List.

2 one empty GameObject in each Scene that cares for the word-creation.
needs a variable to store the reference to the 'Manager'-Script. Search the reference in Start(). (to get the reference, google gameObject.Find and GetComponent and/or 'access variables from another script' or something).
when the word is done, feed it to Manager by calling it's 'FeedWord'Function.

3 the same empty GameObject can have RevisionControl. This needs to reference the ManagerScript and read its Lists, then display them as buttons.

Edit: Oh, well.... -.- here's the code then....

//ManagerScript.js:

var level01Words : List. = new List.(); var level02Words : List. = new List.(); // an new List of Strings is created and assigned to 'lvl01Words'. // this List is currently empty.

function Awake () { DontDestroyOnLoad(transform.gameObject); // have this GameObject survive throughout all scenes. }

/ what the following function does we need a function that will later feed the Words into the empty Lists

we create a function that take two 'Parameters' Parameters are like variables, just that they exist only inside their function. we have to say, of what type these Parameters are for some weird reason, they are separated by ',' insteat of ';' when we call the function, we have to give the appropriate variables in the right order (can't call: FeedWord(someString, someInt); but call: FeedWord(someInt, someString); when calling the function, the values are assigned to the parameter-variable so inside the function FeedWord the variable 'level' has now the value 'someInt' and 'word' has now the value of 'someString' and the function will process that...

**/

function FeedWord (level : int, word : String) { switch (level) { case 1: level01Words.Add(word); break; case 2: level02Words.Add(word); break; default: print("we are neither in lvl 1 nor 2...?"); break; } }

~~~~~~~~~~~~~~~~~~~~~~

//WordCreation.js

var level : int; // set this value in the editor (level1 = '1', level2 = '2' etc.) private var newWord : String; private var managerScript : ManagerScript; // the variable managerScript references the path to a Instance (=Copy) // of your self-defined Class 'ManagerScript'

function Start() { managerScript = gameObject.Find("Manager").GetComponent(ManagerScript); // if possible, reference-paths are always stored in function Start

// depending on how you create the word, you might want to call // function CreateWord in function Start, in function Update or from another Button etc. / CreateWord(); just commented out for demonstration. Once the CreateWord-Function works propperly (= you have added the code that actually creates a word), you have to remove the */

managerScript.FeedWord(level,"Word1"); managerScript.FeedWord(level,"Word2"); managerScript.FeedWord(level,"Word3");

}

function CreateWord () { // do stuff to create your word. When it's done:

//newWord = the newly created word.

managerScript.FeedWord(level, newWord); // adds newWord to the list of level-x-Words in Manager.js }

~~~~~~~~~~~~~~~~~~~~~~~~~~~

//RevisionControl.js

var level : int; // again, set in editor to respective value. // for final revision, set this to any other value. (e.g. '100') private var manager : ManagerScript;

function Start () { manager = gameObject.Find("Manager").GetComponent(ManagerScript); }

function OnGUI () { switch (level) { case "1": DisplayButtons(manager.level01Words); break; case "2": DisplayButtons(manager.level02Words); break; default: // Default assumes we are in final revision and displays ALL words: DisplayButtons(manager.level01Words); DisplayButtons(manager.level02Words); break; } }

function DisplayButtons (levelWords : List.) { for (var i : int = 0; i< levelWords.Count; i++) // create a new variable 'i : int' to use it inside the loop // take 'element 0' (= the first word in the List) and do what is inside the loop, // then take the next element, do what's inside the loop, // ... and so on, until you are through with all elements { if (GUI.Button (Rect((10 + (level-1)*60), (10 + i*30), 50, 20), levelWords[i]))

/ what this last line of code does:

(10+(level-1)*60) sets the x-value of the topleft corner of the new button. if 'level' is 1, then this position is at (10+(1-1)*60) = 10. so all words of level1 draw in the first column at x-position = 10. if 'level' is 2, then this position is at (10+(2-1)*60) = 70. so all words of level2 draw in the second column at x-pos = 70.

(10+i*30) sets the y-value of the topleft corner of the new button. i = the first, second or third etc Word in the List we are currently checking. If i = 0 (=first word), then this pos is at (10+0*30) = 10. So all first words always draw in the top row at y-pos = 10. If i = 1 (=second word), then this pos is at (10+1*30) = 40. So all second words always draw in the second row at y-pos = 40.

levelWords[i]: if i = 0 that's the first Word of the current String-List. if i = 1 that's the second Word and so on.

**/

   // if this button we just created gets clicked, do:
   {
      // load the explaination-page depending on what 'theWord' is
   }

} }

Greetz, Ky.

Comment
Add comment · Show 14 · 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
avatar image missypooh · Jul 28, 2011 at 03:00 PM 0
Share

I would appreciate if you could provide a proper code-syntax. Need it badly as i can't seem to get the logic. Sorry and thank you.

avatar image SisterKy · Jul 28, 2011 at 04:24 PM 0
Share

edited. hrm. 1hr of work...... =/
I did it very verbose, so you should be able to learn a lot from this.
...don't ask for something like that again.

Greetz, $$anonymous$$y.

avatar image missypooh · Jul 28, 2011 at 04:42 PM 0
Share

"Second, whenever player finish level1, they will be proceed to level1Complete which will show them what words they have form in level1. Then i am intending to create a link that will direct them to an "explanation" page which will explain what the individual word mean? So how could i do about it??" -> this question are being ignored :(

avatar image SisterKy · Jul 28, 2011 at 04:58 PM 0
Share

my RevisionControl.js does both level1Complete and a final revision control, so it's an answer to question 2, too.
When you assign '1' for level : int, it's level1Complete-revision.
When you assign '3892' for level: int, it's finalRevision

Please accept and vote for my answer that I regain editing-powers at 2000 Rep.

Greetz, $$anonymous$$y.

avatar image SisterKy · Aug 03, 2011 at 07:38 PM 1
Share

if(GUI.Button(blahblah)) { Application.LoadLevel(levelWords[i]); }

The explanation-scene you want to load needs to have the EXACT SA$$anonymous$$E NA$$anonymous$$E as the word the user created. Then this should work.

Please accept my answer.

Greetz, $$anonymous$$y.

Show more comments
avatar image
1

Answer by SisterKy · Jul 18, 2011 at 08:29 PM

Have one GameObject that won't be destroyed on load, with a Script that stores the Strings in a List. Use custom unity google search ( http://www.google.com/cse/home?cx=002470491425767499270:iugs1ezlsfq ). Search for loadlevel, dontdestroyonload, Array / List and String. Good Luck.

Greetz, Ky.

Comment
Add comment · Show 1 · 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
avatar image _Petroz · Jul 19, 2011 at 06:14 AM 0
Share

http://unity3d.com/support/documentation/ScriptReference/Object.DontDestroyOnLoad.html

avatar image
0

Answer by missypooh · Jul 19, 2011 at 06:21 AM

//revisionControl->create empty object and attach to it on the scene "level1"

 static var lvlStringList    :String[];
 
 function Awake ()
 {
     DontDestroyOnLoad (transform.gameObject);
 }
 
 function Update () 
 {
     
 }    
 
 //displayLevelsWord script that are attached to the scene "revision"
 var level1Words : Transform;
 var level2Words : Transform;
 var level3Words : Transform;
 var level4Words : Transform;
 var level5Words : Transform;
 var level6Words : Transform;
 var level7Words : Transform;
 var level8Words : Transform;
 var level9Words : Transform;
 var level10Words : Transform;
 
 function Update () 
 {
     level1Words.guiText.text +=revisionControl.lvlStringList+ "\n";
         // maybe i don't know how to use the array of string, it display nothing on the scene.
 }

I have try coding it but somehow it doesn't work properly. I don't really know how to use the arraylist or array of string.

Comment
Add comment · Show 8 · 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
avatar image _Petroz · Jul 19, 2011 at 09:09 AM 0
Share

Please do not post followup questions as answers. I fixed up your code formatting, in future please use the '010101' button to format your code properly so people can read it.

avatar image missypooh · Jul 19, 2011 at 11:27 AM 0
Share

hello Petroz, Thank you for helping me. I am really sorry. Just start using this yesterday. So not very familiar. Noted. Will be very careful with it. So anyway how do i go about solving the problem??

avatar image synapsemassage · Jul 19, 2011 at 11:37 AM 0
Share

Next to search field in the upper right corner is Topic called FAQ. Please read it before posting your further questions. "Please help me" is not a question btw.. Community is generously giving help, making communities life easier with good posts is very appreciated.

avatar image missypooh · Jul 19, 2011 at 11:44 AM 0
Share

hi synapsemassage, thank you for the feedback. Will take note of it when i post question and my question title :)

avatar image SisterKy · Jul 20, 2011 at 12:57 PM 0
Share

Arrays and Lists: http://www.unifycommunity.com/wiki/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use%3F

You have to use something along the line of lvlStringList.Add(level1Words.guiText.text + "\n"); (if you use a List)
Or something like levelStringList[0]=level1Words.guiText.text + "\n"; if you use an array.

Greetz, $$anonymous$$y.

Show more comments

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Is it possible to convert c# generic List<> to normal arrays? 1 Answer

How do I find a local variables index in a foreach loop? 1 Answer

How do I animate properties in a List? 0 Answers

Storing away monsters 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