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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Canvas Does Not Update Text Until Closed Out Of Game

Discussion in 'UGUI & TextMesh Pro' started by Happy_Jingle, May 23, 2016.

  1. Happy_Jingle

    Happy_Jingle

    Joined:
    Mar 9, 2014
    Posts:
    103
    I have a text component that is changed in my script, however the change does not appear on the canvas until after I stop running the game. How do I get the change to appear at runtime?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Linq;
    5. using UnityEngine.Networking;
    6. using System;
    7. using UnityEngine.Networking.NetworkSystem;
    8. using UnityEngine.UI;
    9. public class Player : NetworkBehaviour {
    10.     public Text turn_count_drop; //assigned in unity
    11.     int turnCount = 0;
    12.     [SyncVar (hook = "ChangeMyTurn")]
    13.     public bool myTurn = false;
    14.  
    15.  
    16.     void ChangeMyTurn(bool value){
    17.         Debug.Log("CHANGE MY TURN CALLED");
    18.         turnCount += 1;
    19.         Debug.Log(turnCount);
    20.         turn_count_drop.text = turnCount.ToString();
    21.         myTurn = value;
    22.     }
    23. }
    I get the "CHANGE MY TURN CALLED" and turnCount messages in console.
     
  2. Happy_Jingle

    Happy_Jingle

    Joined:
    Mar 9, 2014
    Posts:
    103
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Linq;
    5. using UnityEngine.Networking;
    6. using System;
    7. using UnityEngine.Networking.NetworkSystem;
    8. using UnityEngine.UI;
    9. public class Player : NetworkBehaviour {
    10.     public Text turn_count_drop; //assigned in unity
    11.  
    12.  
    13.     void Update(){
    14.         turn_count_drop.text = "dog";
    15. }
    16. }
    This similarly does not update the text on the canvas.