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. Dismiss Notice

UI text shows in one scene but not in the other

Discussion in '2D' started by Dubalaj, May 22, 2021.

  1. Dubalaj

    Dubalaj

    Joined:
    May 17, 2021
    Posts:
    1
    On my first scene the text doesn't show on the UI , while on my second scene it shows.

    https://ibb.co/q5jj832 (pic for reference)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class Score : MonoBehaviour
    7. {
    8.     public int scoreValue = 0;
    9.     public Text score;
    10.  
    11.     public void IncreaseScore(int increase)
    12.     {
    13.         scoreValue += increase;
    14.         score.text = "Score :" + scoreValue;
    15.     }
    16.     public void Update()
    17.     {
    18.         if(scoreValue == 5)
    19.         {
    20.             FindObjectOfType<LevelManager>().Next();
    21.         }
    22.     }
    23. }
    https://ibb.co/qsnBjzb (pic for reference)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class Score1 : MonoBehaviour
    7. {
    8.     public int scoreValue = 0;
    9.     public Text score;
    10.  
    11.     public void IncreaseScore(int increase)
    12.     {
    13.         scoreValue += increase;
    14.         score.text = "Score :" + scoreValue;
    15.     }
    16.     public void Update()
    17.     {
    18.         if(scoreValue == 5)
    19.         {
    20.             FindObjectOfType<LevelManager>().Menu();
    21.         }
    22.     }
    23. }
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,533
    Unfortunately I have no idea. I will point out for the future though that the UI forums can be found here.
     
    Dubalaj likes this.
  3. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    The first scene the text shows a height of -34 and for the second scene it shows 30. That's probably why it doesn't show up. One other thing you can reuse the top script as they both are the same aside from the name.
     
    Dubalaj likes this.
  4. SadeqSoli

    SadeqSoli

    Joined:
    Jul 1, 2019
    Posts:
    11
    Hi @Dubalaj
    This is seems to be a editor settings problem in position property which can be out of canvas or screen and also width and height MUST be always a POSITIVE number to be visible.
    ***** Hope it will help you ******

    Screenshot_1.jpg
     
    Dubalaj likes this.