Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Please Help Beginner . Overall Help

Discussion in 'Editor & General Support' started by MattCarter24, May 27, 2015.

  1. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    Hello,

    I am 100% new to Unity and only know a little bit of Javascript. i've only ever used this knwoledge in creating the simplest web applications so i've never actually learnt about creating games with JavaScript. Anyway, I've downloaded all the software I need. I would like help to understand the following questions...

    1. How do I optimize the screen which is just blue and blank, to an Android screen size (Galaxy S5). Am I supposed to get a square that represents where the screen is cut off on the outside and what is on the inside shows on the device because I see no distinguishing line that shows what will be displayed or cut off? I am so confused and just want to give up but I'm trying to remain positive.

    2. How do I create a simple game where there are 5 levels (How do I create a level?). Each level will have a question up the top (how do I insert text?). Below the question will be a button that should play 30 seconds of a song. The question asks the user to listen to the song and fill in the missing words. So I'll need a text box for user input(how do i get a text box?). I want a button underneath saying 'check answer' (how do i create a button?) and will bring a pop up message( How do i create a pop up alert?) telling you whether you got the answer correct or incorrect. I then want it to give you a point if it's correct and keep track of the score by displaying it in the top right hand corner of the screen (How do I do this?). I don't know how to use c# either so I'm freaking out as this is an important assignment I need to complete and I'm so blank to begin. I am also probably wrong about the coding required to make that comparison, something like this is what I'd guess but I don't even know where to put these elements like in folders or what? Please help I will be so grateful.

    Please, please, please help!

    Thanks, Matt
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    Make something, that is easy. So you can learn unity.

    1. In uniy editor are Scene tab, Game tab and something other... Choose game tab, left up in the tab is using resolution (i think s5 has 1920*1080, set the resolution to that). Now you can see in game tab, how it will look on s5. (you can download android app unity remote 4 for your smartfon and use it with pc for test. read here:
    http://docs.unity3d.com/Manual/UnityRemote4Android.html

    2. use unity Ui for that.

    File - new scene. You will have new scene where is only main camera

    then GameObject - UI - Text, now you will have place for text in scene, move it, fill it ... make something, what you will :)

    if you need button
    GameObject - UI- Button. and so you have button in your scene :)

    For input, maybe input field, i didnot tryed it.

    AT least you will need little script for check the result. I cannot java, only little c#.
     
  3. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    Thanks you for your prompt answer. When I click file... New scene... Nothing happens please help. How do I move objects like the text and button around? How do I insert a screen where my logo is displayed for a few seconds before the app starts? How do I insert an image or my logo I mean. Thanks, matt
     
  4. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    if you will move something, then switch to "Scene" tab. There are more ways for make logo.

    You can make new scene. Add scene to build (file - build settings - add current).
    Then GameObject -> UI -> Image.
    Import your logo to unity (drag&drop image to assets window).
    Click on Image in Hierarchy window.
    In inspector window you will see options for Image. Look for "Image Script". There is input field Source Image. Drag&Drop your Image from assets folder to this input field. You should see your picture in scene window now.

    "displayed for a few seconds"

    you can make c# script (right clic in assets window, then create c# script). Name it logo. Doubleclick on it, script editor will open.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class logo : MonoBehaviour {
    5.  
    6.     public float logoTime;
    7.     public int levelToLoad;
    8.  
    9.     // Use this for initialization
    10.     void Start () {
    11.         Invoke ("logoEnd", logoTime);
    12.     }
    13.  
    14.     void logoEnd () {
    15.         Application.LoadLevel (levelToLoad);
    16.     }
    17.  
    18. }
    create emptyGameobject (GameObject - create empty). Choose it in Hierarchy. In inspector tab add script logo to this gameobject. Fill inputsfields from this script (logoTime (how long show), levelToLoad (wich level to load after this scene (you can see levels number in "file - build settings". The first scene is 0, so put 1 for next scene).

    if you run now the scene, then you will see your logo in game tab, thin in few seconds (logoTime), you will see error in log (there is no level 1 to load :) ). So save scene. Make new scene and add it to build as 1. In this second scene make your gamelevel.
     
  5. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    Thank you! How do I resize the image and centre it both horizontally and vertically? Also how would I fill in the background with the colour white in the logo scene only?

    As for the next scene. Again, it won't create a new scene??? Please help!

    Thank you! :)
     
  6. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    Hello again, I just built and ran my project on my android device using the unity Remote App and the logo scene didn't appear at all. Only the second scene which was Level 1 where I had a single line of text just to try it out and when I ran it on my phone it doesn't show the logo scene and it skips to level 1 and the line of text is so small you can barely read it! I'm very confused, I don't know what I did wrong. Please Help!

    Thanks, Matt
     
  7. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    What is the weird line also in my screen. in the image below.
    upload_2015-5-28_20-52-6.png
     
  8. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    with "second scene".
    do you have change logo-script in inspector ? Try set logo Time to 10. Or check script for error. The script should not have update funktion.

    "fill in the background.... the line of text is so small"
    on your screen, up from Hierarchy are 5 small buttons. Click last with square and point in it. Then double click on Text in Hierarchy. With the 5 button on, you can make text place bigger. The same with your image (or you can choose image, go to Rect Transform in inspector, click on red cross lines and choose Resize on full screen (right down blue lines).
     
  9. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    Hello, I don't know how to check my code for errors. I don't want the logo in the second scene an it isn't which is good but everything appears to be big in the Game View but when I export to Android it's all tiny. I think I figured out how to fill in the background. I made everything bigger but it is still tiny. It must be the resolution. I entered it in manually with the correct numbers and yet it says 183 by 326 resolution underneath still??
    Is there a way I can upload all my code so that you can look at it. In scene 1 under the logo text I do have an update and I have no connection between the logo and scene two at all???I'm so confused???
    I want to begin by fixing this issue with the screen size first. I've done everything you've said and everything is still bigger on the computer but still very small on the phone . Please tell me exactly every single click on how to set up android screen right from the creating a new project button please.
     
  10. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    There's a weird line going through my blank environment which means there's something not right with the screen size set up. please look at the image I have attached, specifically at the blue work shop area where you will see the blue rectangle. Can you see the weird white line cutting a quarter of it out?
     

    Attached Files:

  11. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    try this project. Click logoscene in asset
     

    Attached Files:

  12. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    I can't extract the uploaded file i don't have the right software???
     
  13. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    i think, you will try adjust your text in wrong place.

    if you add ui to scene, then you have big box up from you scene. Double click on canvas (in Hierarchy), so you can see this box. If you add text to scene, then sometimes it is somewhere in scene, but not in this big box. So drag your textObject in that box. On this box you can see, how your UI will be on display.
     

    Attached Files:

    • UI.png
      UI.png
      File size:
      23.8 KB
      Views:
      757
  14. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    it was .rar archive. I will try .zip now
     

    Attached Files:

  15. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    I unzipped it and it cuts your logo off in the unity program should I try to export to android device?
     
  16. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    Hello, I just ran your project on my phone and everything was tiny just like mine. There must be an issue with the resolution or screen size. I have a Samsung Galaxy S5 and you had the right dimensions earlier of 1080 * 1920. I did enter those but it still doesn't work. Sorry but your project doesn't work either, what do we do now?
     
  17. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    I fixed all of the above errors THANKS! :) Also can you pleas help me by telling me how I would code a score function that adds a point every time you click a button that checks a text fields input and compares it to the pre-set criteria.
     
  18. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    sorry, i didnot used input fields.

    you should add line to your script:
    using UnityEngine.UI;

    and then something like:

    Code (CSharp):
    1.  
    2.  
    3. public InputField inputField;
    4. public String myInput;
    5.  
    6. void Start () {
    7. inputField = GetComponent <InputField> ();
    8. }
    9.  
    10. void Update () {
    11. myInput = inputField.value;
    12. }
    add this script to gameObject with fieldinput (make tag for this gameobject Input).

    make ui button.

    add script with lines (dont forget: using UnityEngine.UI;)
    Code (CSharp):
    1. GameObject otherInput;
    2. public String shouldBeInput;
    3. public int Score = 0;
    4.  
    5. void Start () {
    6. otherInput = GameObject.FindGameObjectWithTag ("Input");
    7. }
    8.  
    9. public void  CheckMyInput () {
    10. if (shouldBeInput = = otherInput.myInput)
    11. score ++;
    12. }
    then in buttons editor click + (add OnClick)

    choose your button in field. choose script "CheckMyInput"

    but as said, i didnot used it, maybe something is wrong.
     
  19. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    Hello @vakabaka could you please reply telling me how to add the score to a UI Text that already exists. Also how do Ikeep the current socre accross multiple scenes? Is that a DontDestroyOnLoad function.
     
  20. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    i would use PlayerPrefs for that, so you can close your game and the score is saved.

    the short version:
    if you you have score (int, float), so befor you load the next level save your score with line:

    Code (CSharp):
    1. PlayerPrefs.SetInt ("Score", score);
    2. //or for float: PlayerPrefs.SetFloat ("Score", score);
    3.  
    4. PlayerPrefs.Save ();
    5. //you dont need this line. Unity will save your score automatically, if new level loadad. But if your game crashes, befor new level is loadad, the score can be lost.
    6.  
    7. //Application.LoadLevel (level);
    8.  
    in next level you can make empty gameobject with script or add this in your score script
    Code (CSharp):
    1. int score;
    2. void Start () {
    3. score =  PlayerPrefs.GetInt ("Score");
    4. }
    5.  
    the long :)

    sometimes you should check your playerprefs, befor you get yor int, float... or you can get error, if there is nothing saved
    i mean something like:

    Code (CSharp):
    1.  
    2. if (PlayerPrefs.HasKey ("Score"))
    3. score =  PlayerPrefs.GetInt ("Score");
    4.  
     
    Last edited: Jun 13, 2015
  21. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
  22. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    try this, but its "little" hard to say, how you can do it, if i can not see all scene :) I am not good at coding.

    Code (CSharp):
    1.     using UnityEngine;
    2.     using System.Collections;
    3.     using UnityEngine.UI;
    4.     public class CheckAnsL1 : MonoBehaviour
    5.     {
    6.    
    7.         public InputField iField;
    8.         string myName;
    9.         string myText;
    10.         public int score = 0;
    11.  
    12. GameObject myTextgameObject; // gameObject in Hierarchy
    13. Text ourComponent;           // Our refference to text component
    14.      
    15.         void Start()
    16.         {
    17.             if (PlayerPrefs.HasKey("Score") == true)
    18.             {
    19.                 score = PlayerPrefs.GetInt("Score");
    20.             }
    21.  
    22. // Find gameObject with name "MyText"
    23.          myTextgameObject = GameObject.Find("MyText");
    24.          // Get component Text from that gameObject
    25.          ourComponent = myTextgameObject.GetComponent<Text>();
    26.         }
    27.      
    28.         public void MyFunction()
    29.         {
    30.             Debug.Log(iField.text);
    31.             myName = iField.text;
    32.             if (myName == "city")
    33.             {
    34.                 score++;
    35.                     Debug.Log("Correct! The word 'city' is correct!");
    36.                 Debug.Log("Your score is now:");
    37.                 Debug.Log(score);
    38.                 PlayerPrefs.SetInt("Score", score);
    39.             }
    40.             else
    41.             {
    42.                 score--;
    43.                     Debug.Log("Incorrect! The answer was 'city'.");
    44.                 Debug.Log("Your score is now:");
    45.                 Debug.Log(score);
    46.                 PlayerPrefs.SetInt("Score", score);
    47.             }
    48.         }
    49.  
    50. void Update () {
    51. ourComponent.text = score.ToString();
    52. }
    53.     }
    54.  
     
  23. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    Thanks @vakabaka I will try the code and let you know how it goes! :)
     
  24. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    I placed the code above in and couldn't play t as the console log just infinitely filled up. Probably because I didn't create a U text or game object for the code. I was so confused. What game or text objects do I need to create and what do I name them??? Please help! @vakabaka

    upload_2015-6-16_19-6-47.png
     
  25. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    I created a game object called myTextgameObject and a UI Text called ourComponent.

    upload_2015-6-16_19-15-22.png

    and the code still doesn't work. Please help! :) @vakabaka @Lee7 @dteerbeest

    The code is below...
    Code (CSharp):
    1.     using UnityEngine;
    2.     using System.Collections;
    3.     using UnityEngine.UI;
    4.     public class CheckAnsL1 : MonoBehaviour
    5.     {
    6.  
    7.         public InputField iField;
    8.         string myName;
    9.         string myText;
    10.         public int score = 0;
    11. GameObject myTextgameObject; // gameObject in Hierarchy
    12. Text ourComponent;           // Our refference to text component
    13.    
    14.         void Start()
    15.         {
    16.             if (PlayerPrefs.HasKey("Score") == true)
    17.             {
    18.                 score = PlayerPrefs.GetInt("Score");
    19.             }
    20. // Find gameObject with name "MyText"
    21.          myTextgameObject = GameObject.Find("MyText");
    22.          // Get component Text from that gameObject
    23.          ourComponent = myTextgameObject.GetComponent<Text>();
    24.         }
    25.    
    26.         public void MyFunction()
    27.         {
    28.             Debug.Log(iField.text);
    29.             myName = iField.text;
    30.             if (myName == "city")
    31.             {
    32.                 score++;
    33.                     Debug.Log("Correct! The word 'city' is correct!");
    34.                 Debug.Log("Your score is now:");
    35.                 Debug.Log(score);
    36.                 PlayerPrefs.SetInt("Score", score);
    37.             }
    38.             else
    39.             {
    40.                 score--;
    41.                     Debug.Log("Incorrect! The answer was 'city'.");
    42.                 Debug.Log("Your score is now:");
    43.                 Debug.Log(score);
    44.                 PlayerPrefs.SetInt("Score", score);
    45.             }
    46.         }
    47. void Update () {
    48. ourComponent.text = score.ToString();
    49. }
    50.     }
     
  26. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    for this script you need to make GameObject-UI-Text
    and name it: MyText


    "I created a game object called myTextgameObject and a UI Text called ourComponent." You dont need that all.

    myTextgameObject and ourComponent are like intern scriptvariable.
     
  27. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    OMG! @vakabaka thank you so much it works!
     
  28. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    One question, how would I get it do display "Score: " before the variable? @vakabaka
     
  29. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    Also can you answer the question below...

    I would like to know what code is necessary to make a pre-existing UI button visible at the end of a pre-existing C# Script. PS: Does this mean the button has to be set to invisible first? How do I do any of this. Is any of this even possible?
     
  30. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    for "Score" just add an other child gameObject - ui text (for text) (or image for picture), and set it on screen, where you will.

    invisible: maybe with disable
    you can add empty gameObject, name it, what you want. Add script to it for child enable.
    then add ui-button to it as child
    disable the child in unity inspector (left-up in unity inspector).

    then you can activate the child button from script in parent gameobject with line in script

    foreach (Transform child in transform) {
    child.gameObject.SetActive (true);}


    i dont know what condition you will use for that.

    i mean something like:

    if (myCondition == true) {
    foreach (Transform child in transform) {
    child.gameObject.SetActive (true); }}
     
    Last edited: Jun 16, 2015
  31. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    Thanks @vakabaka I shall try this when I get the chance! :)
     
  32. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    @vakabaka I tried the code below and got this error message. Please focus on line 48 & 49.

    upload_2015-6-17_18-25-23.png

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. public class CheckAnsL1 : MonoBehaviour
    5. {
    6.  
    7.     public InputField iField;
    8.     string myName;
    9.     string myText;
    10.     public int score = 0;
    11.  
    12.     GameObject myTextgameObject; // gameObject in Hierarchy
    13.     Text ourComponent;           // Our refference to text component
    14.  
    15.     void Start()
    16.     {
    17.         if (PlayerPrefs.HasKey("Score") == true)
    18.         {
    19.             score = PlayerPrefs.GetInt("Score");
    20.         }
    21.      
    22.         // Find gameObject with name "MyText"
    23.         myTextgameObject = GameObject.Find("MyText");
    24.         // Get component Text from that gameObject
    25.         ourComponent = myTextgameObject.GetComponent<Text>();
    26.     }
    27.  
    28.     public void MyFunction()
    29.     {
    30.         Debug.Log(iField.text);
    31.         myName = iField.text;
    32.         if (myName == "city")
    33.         {
    34.             score++;
    35.             Debug.Log("Correct! The word 'city' is correct!");
    36.             Debug.Log("Your score is now:");
    37.             Debug.Log(score);
    38.             PlayerPrefs.SetInt("Score", score);
    39.         }
    40.         else
    41.         {
    42.             score--;
    43.             Debug.Log("Incorrect! The answer was 'city'.");
    44.             Debug.Log("Your score is now:");
    45.             Debug.Log(score);
    46.             PlayerPrefs.SetInt("Score", score);
    47.         }
    48.             foreach (Transform child in transform){
    49.             Button1.gameObject2.SetActive (true);}
    50.  
    51.     }
    52.  
    53.     void Update () {
    54.         ourComponent.text = score.ToString();
    55.     }
    56. }
     
  33. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    maybe 49 line

    child.gameObject.SetActive (true);}

    sorry, here was wrong code
     
    Last edited: Jun 19, 2015
  34. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
  35. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    I changed line 49 and I got this error message...
    upload_2015-6-19_9-17-6.png
    Here is my current code... Do I need 'UnityEngine.Transform' at the top?
    My code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. public class CheckAnsL1 : MonoBehaviour
    5. {
    6.    
    7.     public InputField iField;
    8.     string myName;
    9.     string myText;
    10.     public int score = 0;
    11.    
    12.     GameObject myTextgameObject; // gameObject in Hierarchy
    13.     Text ourComponent;           // Our refference to text component
    14.    
    15.     void Start()
    16.     {
    17.         if (PlayerPrefs.HasKey("Score") == true)
    18.         {
    19.             score = PlayerPrefs.GetInt("Score");
    20.         }
    21.        
    22.         // Find gameObject with name "MyText"
    23.         myTextgameObject = GameObject.Find("MyText");
    24.         // Get component Text from that gameObject
    25.         ourComponent = myTextgameObject.GetComponent<Text>();
    26.     }
    27.    
    28.     public void MyFunction()
    29.     {
    30.         Debug.Log(iField.text);
    31.         myName = iField.text;
    32.         if (myName == "city")
    33.         {
    34.             score++;
    35.             Debug.Log("Correct! The word 'city' is correct!");
    36.             Debug.Log("Your score is now:");
    37.             Debug.Log(score);
    38.             PlayerPrefs.SetInt("Score", score);
    39.         }
    40.         else
    41.         {
    42.             score--;
    43.             Debug.Log("Incorrect! The answer was 'city'.");
    44.             Debug.Log("Your score is now:");
    45.             Debug.Log(score);
    46.             PlayerPrefs.SetInt("Score", score);
    47.         }
    48.         foreach (Transform child in transform){
    49.             child.GameObject2.SetActive (true);}
    50.  
    51.     }
    52.    
    53.     void Update () {
    54.         ourComponent.text = score.ToString();
    55.     }
    56. }
    Please help, thank you.
     
  36. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    @MattCarter24 : Where did you get GameObject2 in line 49 from? That makes no sense.

    try something like this

    Code (CSharp):
    1. child.gameObject.SetActive(true);
    You should start reading the error messages, they tell you what's wrong.

    And another thing : DO NOT DOUBLE POST.
    There is a reason that there is edit button on you post.
     
  37. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    sorry, that was my wrong code with gameobject2. I have just copied the 49 line and changed it :)
     
  38. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    But the code doesn't apply to game object 2 with your line of code @fffMalzbier . @vakabaka . I have multiple game objects and this script isn't attached to the game object in which I wish to have the child enabled. I want the GameObject 2 to be enabled so how can I access a gameobject through code when the script isn't attached to that particular gameobject?
     
  39. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    @vakabaka & @fffMalzbier I have just removed the code as it doesn't work. It just creates more compiler errors. I am try ton activate a child named Button1 in a gameobject called GameObject2 . How can I do this from a script which isn't attached to either of these items? @Lee7 @zteerbeest
     
  40. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    @vakabaka & @fffMalzbier thanks for your help! I fixed all the errors myself! So proud! :) I thank you for your help so far and will contact you if needed in the future! Thanks again!
     
  41. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    Hello,

    I have the code below which works perfectly. I would like to somehow (in a new scene) pull the score variable from the previous code and display it in a UI text. I would also like the new script in the new scene to run automatically without any triggers?

    Any help would be much appreciated!

    Here is my code...

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. public class CheckAnsL8 : MonoBehaviour
    5. {
    6.    
    7.     public InputField iField;
    8.     string myName;
    9.     string myText;
    10.     public int score = 0;
    11.    
    12.     public Text Status;
    13.    
    14.     GameObject myTextgameObject; // gameObject in Hierarchy
    15.     Text ourComponent;           // Our refference to text component
    16.    
    17.     void Start()
    18.     {
    19.         if (PlayerPrefs.HasKey("Score") == true)
    20.         {
    21.             score = PlayerPrefs.GetInt("Score");
    22.         }
    23.        
    24.         // Find gameObject with name "MyText"
    25.         myTextgameObject = GameObject.Find("MyText");
    26.         // Get component Text from that gameObject
    27.         ourComponent = myTextgameObject.GetComponent<Text>();
    28.     }
    29.    
    30.     public void MyFunction()
    31.     {
    32.         Debug.Log(iField.text);
    33.         myName = iField.text;
    34.         if (myName == "castle")
    35.         {
    36.             score++;
    37.             Debug.Log("Correct! The word 'castle' is correct!");
    38.             Debug.Log("Your score is now:");
    39.             Debug.Log(score);
    40.             PlayerPrefs.SetInt("Score", score);
    41.             Status.text = "Correct!";
    42.             Status.color = Color.green;
    43.         }
    44.         else
    45.         {
    46.             score--;
    47.             Debug.Log("Incorrect! The answer was 'castle'.");
    48.             Debug.Log("Your score is now:");
    49.             Debug.Log(score);
    50.             PlayerPrefs.SetInt("Score", score);
    51.             Status.text = "Incorrect!";
    52.             Status.color = Color.red;
    53.         }
    54.        
    55.         GameObject theTargetChild = GameObject.Find("theTargetChild");
    56.         foreach (Transform child in theTargetChild.transform)
    57.         {
    58.             child.gameObject.SetActive(true);
    59.         }
    60.     }
    61.    
    62.     void Update () {
    63.         ourComponent.text = score.ToString();
    64.     }
    65. }
     
  42. MattCarter24

    MattCarter24

    Joined:
    May 27, 2015
    Posts:
    120
    FIXED IT! YAY