Score system?

I’m currently making a game where you controll 1 cowboy and have to shoot another. Like the old atari and comadore game Gun fight

Everything works perfectly and thanks to everyone who helped me so far getting this dream of a game comming true!! as i no longer own a comadore to play it :frowning:

My game is pretty much soon done.

I only need 1 last thing and that is what i call the hardest part of whole this game.
The score system.

I want a text saying P1 that’s easy. And next to that i want a score system

Like this

I want the score to update whenever the bot kills me and he gets 1 point or when i kill the bot and i get 1 point. When either one gets 1 point you /respawn the first guy to 20 wins.

Can someone help me. I’m on bare ground here and have no idea what to do here.

script which holds the two scores, and has an “increase score x by value y” function. This needs to be on a gameobject that isn’t destroyed during the game (called ScoreManager or something).

The scoring event (I’m assuming a use of raycasts or oncollision functions?) need to be able to say ScoreManager.IncreaseScore(x), so that script will either need to find the scoremanager go/script or be given a reference to it.

You then update the canvas elements from scoremanager.

So like this

using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
int score = 0;
public void AddToScore () {
    ++score;
    guiText.text = "Score: " + score.ToString (); 
}
  
    }

??

I just create a new script called

Score

Attach that to a empty gameobject which holds the score text gui?

Add this script to Player and enemy:

public class ScorePoint : MonoBehaviour {
    public int scoreValue = 1;   
    void OnTriggerEnter(Collider collider) {
        if(collider.tag == "Bullet") {
            scoreManazer.score += scoreValue;
        }
    }
}

And this script add to UI text

public class scoreManazer: MonoBehaviour {
public static float score;

void Update(){
GetComponent <Text> ().text = score + " Player";

if (score => 20){
Restart();
}
}
void Restart(){
Application.LoadLevel(0);
}

This is not tested but it should works…

Thanks Johny. Will check it out straight away! :slight_smile:

Hmmm

OOOHHH forget it. I’m stupid.i hadn’t created the other script and that’s why. :smile:

In scoreManazer
dont use “public static float score”
use “public static int score”

Did.

What i did
Added the ScorePoint Script to the player and enemy

Created a new Gameobject - UI - Text
Created the new scoreManazer script but can’t add it to the text yet hence this

It’s just the Get component line there’s wrong. I already have that UI - Text out in my scene. It’s a child of a canvas which was created when i created that Gameobject - ui - text. Hmmmmm

here is it:

using UnityEngine;
using UnityEngine.UI; //THIS!!
using System.Collections;


public class scoreManazer: MonoBehaviour {
    public static int score;
    private float MaxScore;
    Text text; 

    void Awake ()
    {
        // Set up the reference.
        text = GetComponent <Text> ();

    }

    void Update(){
        text.text = "Player " + score;
      
        if (score >= MaxScore){
            Restart();
        }
    }
    void Restart(){
        Application.LoadLevel(0);
    }
}

You must use UnityEngine.UI

Thanks everything seems to be fine without any errors.

So now i just add this scoreManazer script to my Text?

Yes only add scoreManazer to text and Scorepoint add to player… check player and bullets colliders

you’re also going to need to change it to handle two scores, the player’s and the bot’s

Is this the correct text i’m using?

I changed Score = maxscore to 20. as well.

Here’s the text

There are errors in the scoremanazer script… what errors is it throwing

this :slight_smile:

I changed it to a Uppercase S again. Problem is can’t change it by it’s name because it keeps going back to a uppercase.

Fixed it.