Search Unity

[Solved] Question - Score OnGui

Discussion in 'Scripting' started by kholyphoenix1, Nov 18, 2015.

  1. kholyphoenix1

    kholyphoenix1

    Joined:
    Apr 17, 2015
    Posts:
    57
    Hello,

    I have a script to count score.
    Except that it does not update when the item is collected.
    Even if the item having the "tag" according to what is described in the "script".

    Thanks a lot!

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ScoreCounter : MonoBehaviour {
    5.  
    6.     // Variáveis
    7.     int score = 0;
    8.  
    9.     // Iniciar
    10.     void Star() {
    11.         score = 0;
    12.     }
    13.  
    14.     // Atualizar
    15.     void  Update (){
    16.  
    17.     }
    18.  
    19.     // GUI
    20.     void  OnGUI (){
    21.  
    22.         GUI.Box(new Rect(10, 10, 100, 20), "Score: " + score.ToString("0"));
    23.  
    24.     }
    25.  
    26.     // Contador de Pontos
    27.     void OnTriggerEnter(Collider other) {
    28.  
    29.         if (other.gameObject.CompareTag ("Yellow Star")) {
    30.             other.gameObject.SetActive (false);
    31.             score = score + 5;
    32.  
    33.         }
    34.  
    35.         if (other.gameObject.CompareTag ("Red Gem")) {
    36.             other.gameObject.SetActive (false);
    37.             score = score + 50;
    38.         }
    39.  
    40.         if (other.gameObject.CompareTag ("Gold Key")) {
    41.             other.gameObject.SetActive (false);
    42.             score = score + 500;
    43.         }
    44.     }
    45.  
    46. }
    --- Edit ---

    I enabled the option in object "is trigger"
    Solved!
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148