• 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
2
Question by karion · Jun 06, 2015 at 01:24 PM · uicanvasdrag-and-drop

Cannot drag-and-drop ui.text in inspector

Hello, iam morbidly new to unity and i have a problem.

I created a script in which iam holding a public reference to a Text variable.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class enemyScript : MonoBehaviour {
     public Text scoreText;
 
         //...
 }

I also made a Text from UI > Text in the inspector. But when iam trying to assign to the script - which is part of a prefab - i cannot drop the text element into the script's variable. Here's a picture with obligatory giant red arrows: image

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
4
Best Answer

Answer by Mouton · Jun 06, 2015 at 02:23 PM

In order to reference an Object to a prefab, you must be sure the Object is part of the prefab, which in your case is not.

You must create an instance of your "Enemy" prefab, then drag&drop it to your "Score Text" reference.

However, since the references arn't within the parent Prefab, it won't be saved when on you "Apply".

You have to consider your problem another way. What are you trying to achieve ?

[Edit:] Mainly, when you have to deal with recurring informations potentially accessible by many objects (just like UI score), it is a good idea to have a place where you can access to all this informations easily, such as a toolbox in your garage.

You can add a script somewhere in your scene, to implement a "ScoreManager" class with datas you want to store and handy functions to update the UI.

Look at this tutorial, it is exactly about what you are trying to achieve: https://unity3d.com/learn/tutorials/projects/survival-shooter/scoring-points

Comment
Add comment · Show 5 · 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 karion · Jun 06, 2015 at 02:57 PM 0
Share

Just want to add score to the player and showing it on the ui when an enemy is hit and dies. Thought it would make sence to fiddle with it in the enemy script since the collision detection takes place there.

avatar image Mouton · Jun 06, 2015 at 03:17 PM 0
Share

Updated my answer to give you hints on your problem.

avatar image karion · Jun 06, 2015 at 03:40 PM 0
Share

Works like a charms, thanks.

avatar image Josh_Noe · Dec 04, 2016 at 07:52 PM 0
Share

For those who don't want to watch the whole video: Use a static variable to access things globally.

avatar image Sanjay1987 · May 17, 2018 at 01:02 PM 0
Share

@$$anonymous$$outon The best solution that i can get to managing the score.Thanks once again

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I return a Dragged Object From a Layer Group to its Original Position? 0 Answers

Change size of UI canvas image, the best option? 1 Answer

Screen Space - Camera Bug (Buttons does not work) on Unity 2017 0 Answers

How to add total quantity of a score after the changing score Int? 1 Answer

Strange error with UI Screen overlay - no bugs or warning, game can't be played. - GameOverText.SetActive (false); 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