Hey guys, I am currently working on a project for my school where I have to create a game that pushes learning. There will be two parts of the game, the quiz aspect and the headball aspect. I want to make the game in such a way that the score you get in the quiz depends on the time you are allowed to play in the headball aspect.
This is urgent because I am working with a time frame and I would like to complete this project as soon as possible. I am relatively new to Unity and I would appreciate if I could get some headway as to where to get started with this.
Hi Kurt,
I think I was misunderstood there. The scoring system for the quiz is fine. I did it in such a way that after every question there is 10 points awarded. But when I make my headball game I want the ui to have an inputfield where the score on the quiz game will be typed then it will calculate the given time. So lets say if you have a score of 40. The time you can play is 60 seconds and that 60 seconds will be implemented in the game
The time allowed (not time actually used) in one mode is going to be used to calculate the score in another mode? I doubt that’s what you meant.
That’s really important in computer programming. Computers are like evil genies: they’ll grant your wishes, but you need to get the wording of your wishes just right, because they will give you exactly what you asked for (no matter how ridiculous), not what you meant. So if you’re going to do some computer programming, you should get in the habit of describing what you want to happen with mathematical levels of precision.
So…you need help writing a math equation that will convert the score into the allowed amount of time? That equation could be literally anything depending on exactly how you want those quantities to be related. You need to decide what relationship you want.
Or maybe what you really mean is that you need help adding a time limit to your game, and the fact that the limit is dependent on some other variable is just a red herring?
Hi AntiStone,
Thank you for this I have to take describing what I want more accurately. I understand where you’re coming from
Yesss. I want to make a time limit and the time limit should be dependent on a factor in my case which is score, so if you have a score of lets say 40 in the game your time limit will be 50 seconds.
You’re not making much progress in describing what you want.
I said “do you need help with X or with Y?” and you said “yes”.
I specifically pointed out that if you want to convert a score into a time, you need to specify mathematically how that conversion should take place. So far, you have only supplied examples, not a generalizable rule. (And your examples are contradictory.)
Try to break your task down into small, specific steps.
And adding to what @Antistone said above, here are some example ways that 50 could be arrived at from 40. There are obviously an infinite number of ways, but here are common ones in a game context:
40 is looked up in a table and that entry says “use 50 seconds”
Take the score 40 and add 10 to it to get 50 seconds
Take the number 90 and subtract 40 from it and you get 50 seconds.
These all fundamentally will behave differently. #1 gives you the most control but requires you to create a table and tune multiple table entries. Maybe 50 seconds ends up being too much? Maybe someone gets a score of 200000 and your table only goes to 1000… all of these things are critical engineering decisions that only YOU can make.
Unfortunately engineering decisions don’t actually care about time tables: they must be made before you can do meaningful work regardless of your time schedule.
First of all, Thank you for taking your time to help me with this, I’m grateful
I thought of a mathematical conversion so it could be like add +20 to the input. So if input = 40. Time = 60.
Steps would be:
Input Score (lets say 40)
Add 20 to the score and name it time
Store this time value
Set this time value to the time allowed for the football game.
Steps 2 and 3 are essentially just one line of code each, which will end up looking something like this:
public float timeLimit; // A variable for storing the time limit
timeLimit = score + 20; // Set the time limit based on the score
However, I think you’ll find that what you called step 1 is actually about 5-10 steps, and what you called step 4 is actually about 10-20 steps.
To input the score:
You need an input field where the user can type
You need some way to know when the user is done typing and ready to proceed (perhaps a button?)
You need to grab the value that the user typed into the field
You need to convert that value from a string to a number
You need to make sure that the value is valid (e.g. they didn’t type in negative a million, or something like “foo” that isn’t a number at all)
If it isn’t valid, you need to abort and inform the user that they made a mistake.
You may discover you need to add extra flourishes to several of the above steps to make things clear and professional (for example: the input field may need a label explaining to the user what it’s for; the error message saying the user did something wrong may need to eventually go away)
To set the time allowed for the football game…well, if you already have the game done, and you already have a timer for it, so that literally the only thing you need to do is to change how long that timer lasts, then that’s probably only one step.
But if you don’t already have a timer for the game, then you need to build a timer. That’s going to involve:
Keeping track of how much time has passed since you started the game
(Probably) displaying the remaining time some place where the user can see it
Checking whether the elapsed time exceeds the established limit
If the limit is exceeded, stop the game, and somehow communicate to the player what happened
…and each of those probably breaks down into several substeps in its own right (depending on the strategy you use to tackle them). For instance, keeping track of time might involve: make a variable for elapsed time, set that variable to 0 when the game starts, increase that variable by Time.deltaTime each frame while the game is running.
Plus, once you actually try things out, you might discover that you really want some extra features–for example, you might want the ability to “pause” the game, and have your time not run out while the game is paused. (Then you’d modify the above to only add time if the game is NOT paused–plus you need to add new steps for how the player pauses and unpauses the game.)
But generally speaking, any time you find it hard to give a technical description of how something should work, it’s usually a good idea to break it down into even smaller pieces. Most stuff becomes simple if you break it down far enough.
Thank you,
This is the way I’m thinking of making it work because I want this value to be collected and stored and picked up later in another scene, if you get what I mean
UI
Input number into input Field
This number will be named the score
When the “enter” button is pressed, the screen moves to the next scene
Add 20 to the score and call it time limit
Store time limit ( using the line you taught me)
I would want steps 3-5 to happen simulatneously. so the score is converted into timelimit and the next scene loads.
Exhibition ( Gameplay)
It collects the time limit that was stored earlier
Display the value and makes it decrease by time.deltaTime
When timelimit = 0. Game ends
If these are the correct steps. Could you take me through it in terms of converting into a c # script?
or else peruse Youtube for the literally tens of thousands of free Unity tutorials, and build up your programming acumen that way, feeling free to post any specific questions here in this forum, with code and error messages, if applicable.