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
1
Question by BrokenTrainex · May 06, 2015 at 08:16 PM · unity 5textcanvasnot workingno errors

My code will not change Canvas Text at all [No errors]

I set this code up and it doesn't change the Canvas Text at all an it has no errors according to unity.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class HealthManager : MonoBehaviour {
     
     Text Text;
     private int Health=0;
     
     // Use this for initialization
     void Start () {
         Text = gameObject.GetComponent<Text>(); 
     }
     
     // Update is called once per frame
     void Update () {
         Text.text="Health : " + Health;  
     }
 }
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DoTA_KAMIKADzE · May 06, 2015 at 08:19 PM

Bad idea to name your text variable with equal name to Text class...come up with a different name...like:

 Text yourText;

Nevertheless it should work anyway, does an object which contain this script contain Text component as well? Have you set Font and width/height of it so that your text is big enough to be seen?

P.S. To be sure that your component is detected you can verify it like that:

     Text yourText;
     void Start()
     {
         yourText = GetComponent<Text>();
         Debug.Log(yourText != null);
     }
Comment
Add comment · Show 2 · 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 BrokenTrainex · May 07, 2015 at 06:51 PM 0
Share

I have changed the code to:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class Health$$anonymous$$anager : $$anonymous$$onoBehaviour {
     
     Text Health;
     private int Health_int=0;
     
     // Use this for initialization
     void Start () {
         Health = gameObject.GetComponent<Text>(); 
         Debug.Log(Health != null);
     }
     
     // Update is called once per frame
     void Update () {
         Health.text="Health : " + Health_int;  
     }
 }

But I am just a begging to C# thing the Debug thing nothing happened and yes the text is big enough to see as I can see it but its not changing to what I set.

Thanks anyway

avatar image DoTA_KAMIKADzE · May 07, 2015 at 08:53 PM 0
Share

Debug.Log should display info in your Console view.

If it doesn't display anything there then your script is disabled, if it shows false then Text component is absent, if it shows true then everything should work if you can visually see text (e.g. when entered directly in Inspector).

avatar image
0

Answer by Makarei · Oct 26, 2015 at 12:31 PM

The best way is to make sure your text object is called health, if you have a maxhealth its will work better.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
  
  public class HealthManager : MonoBehaviour 
 {
      
      Text health;
      Player player;     

      // Use this for initialization
      void Start () 
      {
          health = gameObject.GetComponent<Text>(); 
          player = Player.player;
          //Debug.Log(Health != null);
      }
      
      // Update is called once per frame
      void Update () 
     {
          health.text = player.health + " / " + player.maxHealth;
      }
  }
Comment
Add comment · Show 2 · 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 Kinger6621 · Dec 30, 2015 at 12:24 AM 0
Share

Update is called 60 times per frame.

avatar image saschandroid Kinger6621 · Dec 30, 2015 at 07:24 AM 0
Share

No, once per frame (and for example 60fps = 60x Update() per second)

avatar image
0

Answer by ProCreeper_2000 · Sep 04, 2016 at 12:35 PM

Should work, did for me!

using UnityEngine; using UnityEngine.UI; using System.Collections; public class HealthManager : MonoBehaviour { Text myText; private int Health = 100; // Use this for initialization void Start () { myText = myText.GetComponent<Text>(); } // Update is called once per frame void Update () { myText.text = "Health : " + Health; } }

@BrokenTrainex

Comment
Add comment · 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

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

7 People are following this question.

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

Related Questions

UI Text Disappears At Some Resolutions 1 Answer

How to create a blinking text and disabling it when the user clicks on the screen.,what would be the code to display a blinking text "TAP TO PLAY" and make it disable when the user touches the screen. 3 Answers

Best way to show image with text next to image target in Unity 0 Answers

using UnityEngine.UI; 'Not necessary' although I need to use 'Text' and '.text'. Also unable to drag-and-drop the Text from my canvas into the 'text' slot. 1 Answer

Unity UI Text with markup tags - “String too long for TextMeshGenerator” 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