Make work with astra

This commit is contained in:
Andras Schmelczer 2026-09-14 08:01:49 +01:00
commit c8ee5045e2
3 changed files with 6338 additions and 4613 deletions

View file

@ -1,17 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class destroyCar : NetworkBehaviour {
public carCount text;
void OnTriggerEnter (Collider other)
{
if(isServer) {
text.IncrementValue();
Destroy(other.gameObject);
}
}
}
fileFormatVersion: 2
guid: 88b7ddbf951e255478383ee9f8ecc0b2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -19,12 +19,13 @@ public class networkManagerCustom : NetworkManager
offlineCanvas.SetActive(true);
offlineCanvas.GetComponent<clientMenu>().errorField.text = "Error: " + conn.lastError.ToString();
base.OnServerDisconnect(conn);
base.OnClientDisconnect(conn);
}
public override void OnClientConnect (NetworkConnection conn)
{
Debug.Log("Simulation client connected to " + networkAddress);
//onlineCanvas.SetActive(true);
offlineCanvas.GetComponent<clientMenu>().errorField.text = "No errors so far.";

View file

@ -1,11 +1,94 @@
fileFormatVersion: 2
guid: ed316f5bd09830c46bd502b7cb2bed3f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 200
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
// Recovered from the bundled Windows server assembly; UNet-generated code omitted.
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class trafficLightColor : NetworkBehaviour
{
private Renderer render;
public float delay = 1.5f;
private Color[] newColors;
private float timeOfUpdate;
private bool dirty;
public float blinkInterval = 1f;
private float blinkTime;
private bool blinkingIsYellow;
private bool areLightsOff;
private Dictionary<string, Color> colorLUT = new Dictionary<string, Color>
{
{
"red",
Color.red
},
{
"yellow",
Color.yellow
},
{
"green",
Color.green
},
{
"off",
Color.white
}
};
private void Start()
{
render = GetComponent<Renderer>();
}
private void Update()
{
if (dirty && Time.time - timeOfUpdate > delay)
{
render.materials[5].color = newColors[0];
render.materials[7].color = newColors[1];
render.materials[4].color = newColors[2];
render.materials[3].color = newColors[3];
areLightsOff = render.materials[5].color == Color.white || render.materials[7].color == Color.white || render.materials[4].color == Color.white || render.materials[3].color == Color.white;
dirty = false;
}
if (areLightsOff)
{
render.materials[5].color = ((!blinkingIsYellow) ? Color.white : Color.yellow);
render.materials[7].color = ((!blinkingIsYellow) ? Color.white : Color.yellow);
render.materials[4].color = ((!blinkingIsYellow) ? Color.white : Color.yellow);
render.materials[3].color = ((!blinkingIsYellow) ? Color.white : Color.yellow);
}
blinkTime += Time.deltaTime;
if (blinkTime > blinkInterval)
{
blinkTime = 0f;
blinkingIsYellow = !blinkingIsYellow;
}
}
[ClientRpc]
public void RpcUpdateColors(string north, string east, string south, string west)
{
if (!dirty)
{
newColors = new Color[4]
{
colorLUT[north],
colorLUT[east],
colorLUT[south],
colorLUT[west]
};
timeOfUpdate = Time.time;
dirty = true;
}
}
}