Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 JayFitz91 · Dec 16, 2014 at 09:34 PM · textdisplay

Issue displaying text on screen

I have 2 characters in my scene, each using the same script. I would like each one to have their own dialogue which I specify in the inspector. I would like each character to display that text when I get close enough to them. This works fine in the console when I use Debug.Log, the console prints the correct message when I'm close enough to the characters.

The problem is, it is only displaying the message on screen for one character but not the other, like so:

alt text

alt text

As you can see, when I get close to the red character, the text and his camera close up is displayed, but with the yellow character, only the camera close up is displayed. What am I missing?

I made the red character and then just copied it to make the yellow on so each character has the same attachments in the inspector.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class showText : MonoBehaviour 
 {
 
     public GameObject player;
     public Button input;
     public Text NPCtext;
 
     public Camera cam;
 
     public string inputField;
     private int size;
 
     public float distance;
 
     void Start()
     {
 
     }
 
     void Update () 
     {
         distance = Vector3.Distance(player.transform.position, transform.position);
         Debug.Log(distance);
 
         if(distance < 5)
         {
             NPCtext.text = inputField;
             input.active = true;
             cam.active = true;
             
         }
         else
         {
             NPCtext.text = "";
             input.active = false;
             cam.active = false;
         }
     }
 }

capture.png (57.1 kB)
capture2.png (38.5 kB)
Comment
Add comment · Show 5
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 LucasMars · Dec 16, 2014 at 09:47 PM 0
Share

Have you set all of the variables (player, input, NPCText, cam, ect) in the inspector? Or maybe you placed the wrong variable (in the inspector). $$anonymous$$ake sure the variables are right.

Can we see screenshots of both of the scripts in the inspector?

avatar image JayFitz91 · Dec 16, 2014 at 09:57 PM 0
Share

Yeah they're all set, I'm certain everything is right. Here's both inspectors:

yellow:

alt text

red:

alt text

As I was saying, in the console, everything works fine, yellow and red characters display the corresponding text, just getting it to display on screen is the issue

capture2.png (25.1 kB)
capture.png (25.4 kB)
avatar image LucasMars · Dec 16, 2014 at 10:03 PM 1
Share

I just realised what is wrong. On the red character, it is disabling the object. Get rid of the line that disables the text, and see if the text changes. It is probably not working, as it is disabled as you walk out of the zone, and you can't re enable it.

avatar image JayFitz91 · Dec 16, 2014 at 10:09 PM 0
Share

Unfortunately that didn't work :/

avatar image LucasMars · Dec 16, 2014 at 10:16 PM 0
Share

Do you disable the text object in any script? To debug the code, comment out that line, and see if the text changes.

If it does, you need to broadcast that the text needs to be displayed (to the other objects). If it doesn't, I'm not sure whats wrong.

1 Reply

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

Answer by SkaredCreations · Dec 17, 2014 at 12:35 AM

At line 38 you're resetting NPCtext.text to empty string, so while the closer is setting to inputField at the same time the other is resetting it. You should use a trigger collider that gives you also more performance than checking the distance at each frame in more scripts (OnTriggerEnter will the the text, OnTriggerExit will reset to empty)

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 JayFitz91 · Dec 17, 2014 at 06:25 AM 0
Share

I see, this makes sense now. Thanks very much, this is working now. @Lucas$$anonymous$$ars, i understand now what you were saying about disabling the text, I would like to thank you also, you guys have been great

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

29 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

Related Questions

How to make GUI Text appear after a certain amount of time 2 Answers

what is the correct way to display text on screen 1 Answer

Trouble displaying lists of strings in a text box 1 Answer

Display a text for all scenes 2 Answers

UI Text not displaying for some game objects when Player is within distance of the object 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