Question by
rdgorodrigo · Sep 08, 2015 at 09:12 AM ·
collectiblecollectible-game-objects
Object Collecting & Points on UI
I want to track the collected object's on the UI, so far I managed to do it by changing the public int to static, but when I change the scene the number remains the same. I just want to make a proper reference to the public int score so that it tracks correctly. Thanks!
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Trofeos : MonoBehaviour {
public int score;
Text texto;
GameObject HUD;
Animator anim;
public AudioSource sounds;
public AudioClip truinfo;
void Start(){
anim = GetComponent<Animator> ();
sounds = GetComponent<AudioSource>();
HUD = GameObject.FindGameObjectWithTag ("Trofeos");
texto = HUD.GetComponentInChildren <Text> ();
score = 0;
}
void Update(){
texto.text = ("Trophies" + score + "/5");
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject)
{
anim.SetTrigger ("Fade");
sounds.PlayOneShot(truinfo,1.0F);
score += 1;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Player (Rigid Body) not collecting/picking up GameObject (Cube) 0 Answers
(2D) Collectible Objects using Raycasts 1 Answer
Item Collection with Raycast / C# 1 Answer
Word Space Text Appearing after Collecting the Object 1 Answer
How to make certain collectibles have to be unlocked before being able to be picked up? 1 Answer