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. Dismiss Notice

Getting UI -> text in script field

Discussion in 'UGUI & TextMesh Pro' started by KingfisherWyvernStudio, Jan 26, 2015.

  1. KingfisherWyvernStudio

    KingfisherWyvernStudio

    Joined:
    Oct 5, 2011
    Posts:
    323
    Hey all,

    I'm still struggling along the path of the Roll-a-ball Tutorial. I've been trying to figure out what I'm doing wrong now. Here's the thing. I've made the text game object Count Text. I have the following playercontroller script:
    code with UI elements.png
    I think point 2 and 3 are correct and point 1 is incorrect. If I shouldn't use GUI, than what should I use?

    My problem? I can't seem to be able to do what I should be able to do, apparently: Link the script and the Count Text. I should be able to drag & drop the Count Text game object into the Count Text field in the player control UI field:
    get Count Text player script field.png
    But as you can see in the "Select GUIText" selection overview, there's nothing to select. Also, I can't drag & drop the game object into the field Count Text. I assume something is wrong in my code, but I have no idea how to fix this.

    And of course I now get an errormessage in the console:
    UnassignedReferenceException: The variable countText of PlayerController has not been assigned.
    You probably need to assign the countText variable of the PlayerController script in the inspector.
    PlayerController.SetCountText () (at Assets/Scripts/PlayerController.cs:38)
    PlayerController.Start () (at Assets/Scripts/PlayerController.cs:13)​
    This is pretty logical since I can't seem to be able to add the reference.

    How do I solve this?

    Thanks for the help!
     
    Last edited: Jan 26, 2015
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    The Roll-a-ball tutorial just covers Legacy GUI, the instructions do not work for the new Unity UI.
    However you can check out this update video from one dev, who walks through creating the UI for the sample using the new platform:
     
  3. KingfisherWyvernStudio

    KingfisherWyvernStudio

    Joined:
    Oct 5, 2011
    Posts:
    323
    Thanks for the help! I'm going to check out these new video's you linked here and my other topic! I'm glad you're all so helpful :) It's good to have people around who can help out newbies with the program!
     
    SimonDarksideJ likes this.
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    Well there is a book coming out on the new system VERY soon :D
     
  5. KingfisherWyvernStudio

    KingfisherWyvernStudio

    Joined:
    Oct 5, 2011
    Posts:
    323
    Oh, That's good! I'll definitely check that out! And I see you've written it. Nice! And Congrats :)
     
    SimonDarksideJ likes this.
  6. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    Simply change this:

    Code (csharp):
    1. public GUIText CountText;
    to this:

    Code (csharp):
    1. public Text CountText;
    (I know it's old, but the answer is simple and this is the only thread I found asking about this specific issue, which I just bumped into briefly. Maybe it'll help someone else.)