|
I got a little bit further with scripting and decided to make a small rpg, now im trying to just set up a script to cast Fire ball. i'm making a fault somewhere, just can't quite seem to find where. } Btw, this is just to make the loading barr work, you know, for charging spells, i know the GUI.box is in the wrong place, but it doesn't even show my Debug.Log, so im trying to figure out why it's not going through the loop
(comments are locked)
|
|
I've not found the reason why Debug.Log isn't printing anything, but the whole thing is wrong: you can't block Unity with a lengthy for like this (not to mention the GUI.Box inside Update) - nothing will happen while this for is counting time. You could something like this instead:
float timeBox = 0;
void Update ()
{
if(Input.GetKeyDown(KeyCode.G)) // if g pressed...
{
timeBox = castTime; // start the timer
}
if (timeBox >= 0) // decrement timer while its >= 0
{
timeBox -= Time.deltaTime;
}
}
void OnGUI()
{
if (timeBox > 0) // display the box while timeBox > 0
{
GUI.Box(new Rect(Screen.width / 2 - 50, Screen.height * 0.9f, castTime / curCastTime, 50), curCastTime + "/" + castTime);
}
}
Thank you a lot, i made the mistake of not attaching it to an object, so the script wouldn't be excecuted. and its true, when i did attach it, my game just crashed for a few seconds and than the bar was suddenly there, i thank you a lot for this script, i can continue now
Nov 19 '11 at 10:50 PM
runetimon
Remember to "accept" the answer before you leave.
Nov 19 '11 at 10:51 PM
OrangeLightning
How excactly do i do that :S, im sorry im fairly new here
Nov 19 '11 at 11:03 PM
runetimon
Click the "check" button below the voting thumbs in the answer. It's important to accept the answer: it helps other people to find solution for similar problems.
Nov 20 '11 at 03:47 AM
aldonaletto
(comments are locked)
|
