You can see my small script below. It simply resets the players position when they fall below a certain height and adds one to their death count and also the team’s death count.
using UnityEngine;
using System.Collections;
public class Scoring : MonoBehaviour
{
public float lowestFallDistance = -10;
private int deathCount;
public static int teamDeathCount;
private string deathCountString;
public static string teamDeathCountString;
private int screenWidth;
void Start()
{
deathCount = 0;
teamDeathCount = 0;
deathCountString = deathCount.ToString();
teamDeathCountString = teamDeathCount.ToString();
screenWidth = Screen.width;
}
void Update()
{
if(this.transform.position.y < lowestFallDistance)
Reset();
}
void OnGUI()
{
GUI.Label(new Rect(5, 5, 30, 20),deathCountString);
GUI.Label(new Rect(screenWidth - 35, 5, 30, 20),teamDeathCountString);
}
void Reset(){
this.transform.position = new Vector3(0,2,0);
++deathCount;
networkView.RPC("PlusTeam", RPCMode.AllBuffered, "");
deathCountString = deathCount.ToString();
}
[RPC]
void PlusTeam(string empty) {
++teamDeathCount;
teamDeathCountString = teamDeathCount.ToString();
}
}
The team’s death count in the top right only shows once, and just as I intend it to, but the player’s individual death count in the top left is always zero with the actual count displayed on top.
This only happens when I play online. If I play single player and die it just shows the correct score without a zero underneath. I really don’t see what I’ve done wrong so any help would be greatly appreciated.