Hello my name is Florian (14) and I’m making my first game, it’s a maze game.
And i have made a timer that stops if you crossed the finish line.
This is my script for the timer:
Hey Florian, welcome to the Unity community! I hope you’re having a great time.
To get data (such as the finish time) from one scene to another, there are a couple of ways to do it. But probably the easiest is to use PlayerPrefs. Check out the examples under PlayerPrefs.SetFloat and PlayerPrefs.GetFloat, and that’s pretty much what you need to do.
One little thing, please use code tags when posting code. That will give us nice indentation, syntax highlighting, and line numbers so it’s easier to read and refer to.
Good luck, and if you have any more trouble, don’t hesitate to ask!
Nigey suggested a solution in the post above by using the user preference.
You can also used a static variable to store the best time. It’s a simple solution but it won’t save the score permanently. The score will reset when you quit the game. But you can do that for testing, and later on implement a more permanent solution.
Assets/Scripts/finish.js(17,43): BCE0017: The best overload for the method ‘UnityEngine.PlayerPrefs.SetInt(String, int)’ is not compatible with the argument list ‘(System.Object)’.
Well, just look at each line it’s pointing you to. (In fact, if you double-click the error in the Console, it should take you directly to the problem line.) The first one is this:
PlayerPrefs.SetInt("brickScore". score);
First, you have a dot there instead of a comma between the arguments. That won’t do! Second, what is this “score” you speak of? I don’t see it declared anywhere. A variable must be declared someplace before you can refer to it.
That applies to line 15, too. As the error says, “timerText” is an unknown identifier. The compiler’s never heard of it; I never have either. So what is it supposed to do with that?
I think you need to put away that tutorial; it’s not helping you, and in fact it’s teaching you some bad habits (like using OnGUI and JavaScript, neither of which I would recommend). Just take it step by step — one little thing at a time. Go back to your first script, which was in C++, and which I think at least compiled. What’s the next step that you want to do?
What do you mean with 'what’s the next step that you want to do?
But how do i need to start then? I’m very bad in scripting and I’m learning everything on youtube but that’s not the best way to learn scripting.
What should I do next?
Exactly what I said. Is your game done? If so, great! If not, then what’s the difference between your game-when-it’s-done and your game-as-it-is-now? And out of all those differences, which is the next one you want to resolve?
In other words, what is the next thing you are trying to accomplish?
Well, you should probably go through some C# tutorials if you haven’t already. I recommend learncs.com.
Then, come back to your project, and start by defining what it is you’re trying to do. Not like “I want to finish this maze game” but more like “I want to store the time from this timer here and display it in that Text over there when you relaunch the game.”
If you can’t define what it is you’re trying to do in any detail, then you won’t be able to do it, nor will we be able to help you.
Most of programming is just thinking clearly about what it is you’re trying to do!