- Home /
Question by
DiegoPower · Aug 24, 2014 at 09:43 PM ·
guitext
How not to show text when colecting all items?
I have 5 items in my level and when I collected one text show up on the screen. I would like for the text to appear when I collect the first 4 items of my level and no text when I collect the last one. How can I do this? Here is my code I have on my items.
using UnityEngine; using System.Collections;
public class Item : MonoBehaviour {
//Variables for text output on screen and audio
public GUIText TextOutput;
public AudioClip SoundToPlay;
//Variables for the item pieces
public static int itemCounter = 0;
//Code for when the player collides with an item to collect.
void OnTriggerEnter (Collider other)
{
//When the Player enters the area
if (other.tag == "Player")
{
//The audio will play
AudioSource.PlayClipAtPoint (SoundToPlay, this.transform.position);
//Text will appear on screen
TextOutput.text = "Look around the town for more pieces!";
//Will increase the item count by one
itemCounter += 1;
//Simulate collection by destroying the item
Destroy (gameObject.transform.parent.gameObject);
}
}
}
Comment
Best Answer
Answer by AlwaysSunny · Aug 24, 2014 at 11:56 PM
if (itemCounter < 4) TextOutput.text = "Look around...