Hi guys, I’m currently facing some problems with my assignment. It would be great if any of you could help. In the game, the player is able to pick up 3 items and whenever he picks up one, a GUI Texture will appear on the screen to notify the player that he got the item. However, the GUI Texture only appears once and when the player proceeds to pick up the other two, the GUI Texture did not appear.
Below is what i have: (Updated Script)
var Picked : AudioClip;
var showGUI = false;
var first : Texture2D;
var color : Color;
function OnControllerColliderHit(hit:ControllerColliderHit) {
if(hit.gameObject.tag == ("Pickable")) {
showGUI = true;
audio.PlayOneShot(Picked);
Destroy (hit.gameObject);
}
}
function Start()
{
color = Color.white;
yield FadeOutAfterTime(5);
}
function OnGUI () {
if (showGUI) {
GUI.color = color;
GUI.DrawTexture (Rect (450,175,375,250), first, ScaleMode.ScaleToFit, true);
}
}
function FadeOutAfterTime(time : float)
{
yield WaitForSeconds(time);
yield Fade();
showGUI = false;
color.a = 1;
}
function Fade()
{
while (color.a > 0)
{
color.a -= Time.deltaTime;
yield;
}
}
All 3 of my items had been tagged “Pickable” so it really baffles me why this script could not work.
However, I was wondering if the reason why the GUI Texture only appears once is because of the fade effect?
Could anyone enlighten me? Thanks in advance.
EDITED:
It seems that showGUI = false and color.a = 1 must stick together or the second texture would not appear.
Thanks in advance!