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

3DText instead of GUIText?

Discussion in 'Scripting' started by Fersutagames_, Nov 13, 2015.

  1. Fersutagames_

    Fersutagames_

    Joined:
    May 2, 2013
    Posts:
    52
    hey guys! Just curious to how / if i can change my script to update 3d text rather than having gui text which is just a pain when wanting to publish to multiple devices :(

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Score : MonoBehaviour {
    5.  
    6.     static int score = 0;
    7.     static int highScore = 0;
    8.  
    9.     static Score instance;
    10.  
    11.     static public void AddPoint() {
    12.         if(instance.bird.dead)
    13.             return;
    14.  
    15.         score++;
    16.  
    17.         if(score > highScore) {
    18.             highScore = score;
    19.         }
    20.     }
    21.  
    22.     BirdMovement bird;
    23.  
    24.     void Start() {
    25.         instance = this;
    26.         GameObject player_go = GameObject.FindGameObjectWithTag("Player");
    27.         if(player_go == null) {
    28.             Debug.LogError("Could not find an object with tag 'Player'.");
    29.         }
    30.  
    31.         bird = player_go.GetComponent<BirdMovement>();
    32.         score = 0;
    33.         highScore = PlayerPrefs.GetInt("highScore", 0);
    34.     }
    35.  
    36.     void OnDestroy() {
    37.         instance = null;
    38.         PlayerPrefs.SetInt("highScore", highScore);
    39.     }
    40.  
    41.     void Update () {
    42.         GetComponent<GUIText>().text = "" + score;
    43.     }
    44. }
    cheers guys! :)
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  3. Fersutagames_

    Fersutagames_

    Joined:
    May 2, 2013
    Posts:
    52
    Sweet thanks hpjohn! Ill take a look into it