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
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.
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?
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
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);
}
}