Hi everyone and a good day.
In my game if the player presses a button they enter a “Bonus Stage” which is really just a 10 second count down where they have to decide which option, out of a totla of two, they are going to choose after the timer has reached zero.
So:
- How can I make a timer?
- What is a relatively streamlined way to attach a series of images (a lightsaber gradually turning off over 10 images for instance) to the timer so that I can display the timer in a gauge rather than numbers (i have the lightsabre images already made).
- Can I deactivate all keystrokes during this 10 second period?
An answer to one or several of these questions would make me love you more than Elvis liked sandwhiches.
Cheers heaps,
BeN
hi, ben.
the answers to your questions are very long. However, all that you planned to do are possible.
a. timer
var timeCount = 0.0;
function FixedUpdate() {
timeCount += Time.deltaTime;
}
Attach this to a game object so you would see the timeCount value updating in the inspector pane.
b. What is a relatively streamlined way to attach a series of images (a lightsaber gradually turning off over 10 images for instance) to the timer so that I can display the timer in a gauge rather than numbers (i have the lightsabre images already made).
Uhmm… I think the Third Person Platforming tutorial starring Lerpz (provided by unity3d) teaches this best. So, go and download it. But to give you a general concept, you are going to use a texture 2D array (Texture2D[ ]).
var timeCount = 0.0;
var indx = 0;
var image : Texture2D[ ];
var position = Rect(10, 10, 100, 100); //your
timer’s position
function FixedUpdate() {
timeCount += Time.deltaTime;
indx = Mathf.CeilToInt(timeCount);
}
function OnGUI() {
GUI.DrawTexture(position, image[indx-1]);
}
c. Can I deactivate all keystrokes …?
Of course, just do a boolean condition
Thanks a bunch for your speedy reply. Yea I’ve got a counter at the moment which starts off at the press of a button. Then when it hits 3 seconds it changes a variable or two, stops and resets. But I’m fairly certain I’ve done it in the most clumsy way possible (code bashfully pasted below).
I’ve done the Lerpz Tute and I’ve used the “PieHealth” meter method used in it several times, however the problem I’m having is converting the timer’s float in to an integer that will work with the array. I assume that one of the lines that you’ve posted that I’m not familiar with does that, so I’ll go have a gander at them momentarily.
So basically what I’m saying, with far too many words, is “Thanks for the help I’ll check out that code.”
Ben
var sand = "s";
var timer : float = 0;
var timerMultiplier = 0;
var prefix = "";
function Update ()
{
timer += (Time.deltaTime) * (timerMultiplier);
if (Input.GetKeyDown ("v")) {
timerMultiplier = 1;
}
if(timer >= 3) {
sand = "t";
timerMultiplier = 0;
timer = 0;
}
guiText.text = prefix + sand;
print (timer);
}
HA! You’re a legend. May all your lootable corpses be laden with phat lewtz.
Out of interest, what converts the float to integers? Mathf.CeilToInt?
Cheers again,
My game is now awesome and is going to make me richer than god.
BeN