Hi,
I was following a tutorial on making a scorelist and I tried to modify it so it could work for up to 4 players.
But when I start the game the text isn’t showing. although the code gets executed, I can tell by the console.
(video) https://i.gyazo.com/ebd7a6fa33b34730d095a631b4ad7178.mp4
Here’s how the score object is set up:
This is the score script that should change and display the score (console part is working):
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour
{
public int score = 0; // The player's score.
private int previousScore = 0; // The score in the previous frame.
void Update ()
{
// Set the score text.
GetComponent<GUIText>().text = score + " kills";
// Set the previous score to this frame's score.
previousScore = score;
Debug.Log("SCORE: " + score);
}
}
This is how I can the referenced score objects:
using UnityEngine;
using System.Collections;
public class ShotPlayer : MonoBehaviour {
private int playerNum;
private Score score1;
private Score score2;
private Score score3;
private Score score4;
void Awake()
{
//Setting up the referenses.
score1 = GameObject.Find("p1_score").GetComponent<Score>();
score2 = GameObject.Find("p2_score").GetComponent<Score>();
score3 = GameObject.Find("p3_score").GetComponent<Score>();
score4 = GameObject.Find("p4_score").GetComponent<Score>();
}
public void Hurt(int playerWhoShotMe)
{
playerNum = playerWhoShotMe;
Debug.Log("I got shot by: " + playerNum);
if (playerNum == 1)
score1.score += 1;
else if (playerNum == 2)
score2.score += 1;
else if (playerNum == 3)
score3.score += 1;
else if (playerNum == 4)
score4.score += 1;
}
}
So I’m missing something and can’t seem to find out what… Been looking at it for roughly 2 hours, maybe a new set of eyes can sort this out.
Thanks allot guys!