- Home /
2D texture for 2 seconds on screen?
Hi guys do one of you know a script so that if I have for example collected 200 coins a 2dtexture comes up and leaves after 2 seconds? ty!
Answer by fafase · Apr 06, 2012 at 05:51 PM
You could create a GuiTexture. Position it where you want it. Then:
var texture : Texture2D;
var On:boolean;
function Start(){
guiTexture.enabled = false;
}
function Update(){
if(coins==200){
On=true}}
if(On){
GuiGoesOn();}
function GuiGoesOn(){
On=!On;
guiTexture.enabled=true;
yield WaitForSeconds(2);
guiTexture.enabled=false;
}
Now is your coin counting in the same script? Is it a static variable?If yes, call the static with
ScriptName.countVar
If not static, you still can send a message from the script where the counting happens. Somehow like this
in the GuiTexture script
var texture : Texture2D;
function Start(){
guiTexture.enabled = false;
}
function GuiGoesOn(){
guiTexture.enabled=true;
yield WaitForSecond(2);
guiTexture.enabled=false;
}
In the script where coins are counted:
function Update(){
if(coins == 200)
{
On = True;
}
if(On){
gameObject.Find("TheGUItextureObject").SendMessage("GuiGoesOn");
On=!On;
}
}
I edited a little as I realized that it could work but would not be the best.
Can I ask How add a random aaray of texture 2d in this script?
@i2naok8 I answered this issue here: http://answers.unity3d.com/questions/446328/play-random-music.html.
It is for music clip but you just need to modify it for Texture2D. If you need more info, you need to post a question on it as it is not related to this thread.
Answer by santelia · Apr 06, 2012 at 05:57 PM
I'm rather newbe, but maybe using Playmaker and global variables can be a breeze.
Answer by TheFrankman123 · Apr 06, 2012 at 05:57 PM
Best off using a particle emitter and set it so it only fires one object and has a life of 2 seconds. Simples.