This commit is contained in:
Andras Schmelczer 2026-09-13 20:53:11 +01:00
commit 36a53f343e

View file

@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
/* A pályát elhagyó autókat (robbanás nem számít) számolja, és írja ki a 3D textbe.
*/
[NetworkSettings(channel = 0, sendInterval = 0.5f)]
public class carCount : NetworkBehaviour {
[SyncVar]
public int throughput = 0;
//Csak akkor updateli a szöveget, ha szükséges.
private int previous = 0;
public void Update ()
{
if (isServer) return;
if(throughput != previous)
{
previous = throughput;
GetComponent<TextMesh>().text = throughput.ToString();
}
}
[Server]
public void IncrementValue()
{
throughput++;
GetComponent<TextMesh>().text = throughput.ToString();
}
}