Create GUI Text, Attach time/distance based score script, Save highscore!!! BEGGING!!

Hey, first of all thanks for clicking on this!

I know there’s a lot of stuff about this but I’m so retarded that I can’t make it happen.

The last piece of my puzzle, a 2d android game, is a scoring system, that is attached to a GUI text, because I want to fiddle with the settings and fonts from there.

I need a scoring system based on time since the level loaded or travelled distance

I need the highscore to be saved, stored between scenes and after game is quit.

I need the highscore to be displayed on the GUI just for a period of time until it disappears

Thank you very very much, I am so desperate about this I am willing to pay for the script or at least add the person to the credits and praise them before I go to bed for a few weeks.

This should help you with saving and getting a high score:
http://answers.unity3d.com/questions/546072/how-do-i-save-high-scores-in-my-game.html

For the time since the level loaded try this:
http://docs.unity3d.com/Documentation/ScriptReference/Time-timeSinceLevelLoad.html
If you’re looking to have the score correlate with the time just make a public variable to store the time in (or store it in player prefs temporarily if you’re switching scenes) and when you want to display a score have a script do some math to calculate score out of the elapsed time and display it via gui text. Put a simple timer on the gui text to make it display for a short time and when that time ends make it remove the gui text and switch scenes or whatever you want it to do.

I can’t give you much advice on score correlating to distance traveled since I don’t know how the traveling occurs, but you could possibly measure the units from the starting position to the ending position if you store the transform of the player object before it ever starts traveling and compare it to its transform position when it stops traveling. If it’s a scroller and the player isn’t actually traveling any number of units you’ll have to find another way to measure it.

Didn’t help… I feel like I’m done with this unity thing

If you show us the code in question, it’s easier for us to help.

I want this to be displayed using GUI text, but from outside of the script
Also I want the highscore to be saved between scenes and after quit

var score : int;

function Update () {
score = Time.time;
}

You could try something like this:

public class ScoreController : MonoBehaviour {

    private float score; // Time.time is a float, not an int

    // Initalization
    void OnStart () {

        // Retrieve the score
        score = PlayerPrefs.GetFloat( "score", 0.0f ); // default score is 0.0f

    }

    // Display the score
    void OnGUI () {

        GUI.Label( new Rect( ... ), score.ToString() ); // Give new Rect() the position and size

    }

    // OnDestroy (ie. when the player quits)
    void OnDestroy () {

        // Save the score
        PlayerPrefs.SetFloat( "score", Time.time );

    }

}

Also, if you need the “score” variable to update real-time, you need to update it inside the Update() or FixedUpdate() method.

You need to use PlayerPrefs to save your highscore.

But i’m wondering how you made your game if you can’t code what you said? You found the scripts on the Internet?

Thank you but how do I make it show using external gui text component?

What do you mean by “external gui text component”? Can you show us that part of the code, as well?

I just showed you everything I have, I don’t know what you don’t understand, I want the score displayed using GUI Text

Yes, and that’s done inside the OnGUI method. Have you even tried my approach? If you did, what didn’t work as expected?

Well the score doesn’t show on the GUI, that’s what didn’t work as expected and I don’t know how to implement it. I want the script to try and access GUI Text from outside the script.

Can you please post the relevant code you’re having at this point?

It’s the one you wrote…

To which object have you attached that script? Did you also create the Update() - or FixedUpdate() - method for updating the “score” variable?

I HAVEN’T! I am new to all this I don’t know how that’s why I’m here on the forums

Then I suggest you look into more Unity3D tutorials, because you need to understand the basics before starting with the more advanced stuff.

In your example, I would assume that you have a Player GameObject of some sort. On that Player object you can add components. If you created a C# called ScoreController (or whatever) based on my code, and added that script (ref. “Add Component”) to the player, you would probably get closer to where you want to be.

A little effort goes a long way. You literally posted code that assigned Time.time to a variable and then said “how come this doesn’t display my highscore in a GUIText and save it?” Also - writing things like “DESPERATE” and “BEGGING” in your topic titles isn’t going to make people respond to you faster.

Have you done the tutorials in the Learn section?
Have you read the manual section on GUI scripting?
Have you read the API documentation for GUI and PlayerPrefs?

I dont know what you want from me I already said I’m retarded.

Also - grow up and use mature/professional language please.