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 /
  • Help Room /
avatar image
0
Question by MrAmazing · Nov 08, 2015 at 07:09 PM · uigetcomponentmenuuser interfacescore system

UI: 'GetComponent' not showing up in Inspector.

Hello,

I'm trying to build a Game Over Screen with the newer UI, and I followed the same steps that I used while setting up my Title Menu, but for some reason I'm having an issue. In the Inspector where the 'GetComponent' will usually have spaces to drag in buttons and a canvas, there is just a space displaying the 'GameOver' Script.

Here's the one I have that's working, for reference: alt text

And here is the one that I'm having issues with: alt text

I'm really not to great with code, but perhaps I haven't told my script to expose them to the inspector? If I've done something completely wrong in my code, please let me know so I can improve! Here is a copy of my code:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class GameOverUI : MonoBehaviour {
 
     int score = 0;
     private bool retry;
 
     public Canvas gameOver;
     public Button retryLevel;
     public Button returnMain;
 
    
     void Start ()
     {
         score = PlayerPrefs.GetInt("Score");
         gameOver = gameOver.GetComponent<Canvas>();
         retryLevel = retryLevel.GetComponent<Button>();
         returnMain = returnMain.GetComponent<Button>();
         gameOver.enabled = true;
     }
     
     public void RetryLevel()
     {
         Application.LoadLevel(1);                    //Level that is my game
     }
     public void ReturnToMainMenu()
     {
         Application.LoadLevel(0);                    //Level that is the Title Menu
     }
 }
 

Also, you will probably see I have a variable declared for 'score' that isn't used in the code. I have a high score that grows based on time that's passed, and amount of power-ups picked up, and would like to add that to my 'Game Over' screen, but am not sure how. Any advice there would be great also!

good-example.png (7.8 kB)
bad-example.png (4.8 kB)
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 Cepheid · Nov 09, 2015 at 12:17 AM

Have you tried removing and re-adding the script or even restarting the Unity editor? Sometimes the Inspector has some weird serialization issues which are usually fixed for me by re-opening the editor or re-adding a script. I say this because, when I copy and pasted your code into my own test project. The fields appeared in the Inspector just fine. Here's an example:

alt text

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 MrAmazing · Nov 09, 2015 at 05:18 PM 0
Share

Wow, it really was just as simple as that... Is this a common problem with Unity? Are there other areas that this problem pops up that I should keep an eye out for?

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

41 People are following this question.

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

Related Questions

Responsive UI 0 Answers

Dynamic Menu C# 0 Answers

How do I keep two UI text unity3d on the scene 2 Answers

Reset Text 1 Answer

Problems to add an object to a scroll list 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