Hi, what I mean by “blinking” is that I want that a GUI button appears on the screen showing the spacebar being pressed and unpressed, showing that the player has to tap the spacebar very fast. How could I make it so that a GUI change itself with other so that an “animation” occurs?
1 Answer
1You can use a MovieTexture in a GUI.DrawTexture function and call myTexture.Play() to make it play. Alternatively, you can have an array with all the keyframes and use something like this
var keyframePointer:int=0;
var delay:float=0.1;
var timePointer:float=0;
var myKeyframes:Texture2D[];
function OnGUI(){
if(showTexture){
GUI.DrawTexture(myRect,myKeyframes[keyframePointer];
if(timePointer<Time.time){
keyframePointer++;
timePointer=Time.time+delay;
}
}
}
I apologise for not being able to format the code properly. Doing so on mobile is a pain.
– Professor_SnakeThanks for the quick response, but in a part of the code you worte %, is i used for something or is it a mistake?
– OrloffyeahOf course, this is a somewhat complex way of incrementing the value. Here is a more simple way that also has a delay variable: var keyframePointer:int=0; var delay:float=0.1; var timePointer:float=0; var myKeyframes:Tezture2D[]; function OnGUI(){ if(showTexture){ GUI.DrawTexture(myRect,myKeyframes[keyframePointer]; if(timePointer<Time.time){ keyframePointer++; timePointer=Time.time+delay; } } } Edit: Updated my answer with this piece of code instead of the other one.
– Professor_SnakeThanks for all the time that you put into explaining this to me, I already tested it and it works! I really appreciate that you explained every bit and in a very detailed way. Thanks once again and have a nice day.
– Orloffyeah
Call a function that toggles a boolean variable after a certain amount of seconds and display the GUI depending on the variable state. e.g.: if(displayGUI) { GUI.Button(....); } You can use [InvokeRepeating][1] to call a function at a set interval [1]: http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.InvokeRepeating.html
– ByteSheep