I will try since my code is quite a mess :>
So i have 2 Main objects, the main mech/the world itself and one for the trigger points.
Both have a lot of childs but in case of the main mesh it shuld be irrelevant.
The world has this script (i try to simplify it that it might be more readable and hope to not cut the error along):
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class WakeUp: NetworkBehaviour {
public Color inside = new Color(0.05490196f, 0.02352941f, 0.03137255f, 1f);
public Color outside = new Color(0.9411765f, 0.7529412f, 0.7529412f, 1f);
private Color bday = new Color(0.02352941f, 0.03529412f, 0.5294118f, 1f);
[HideInInspector] public bool nighttime = false;
[HideInInspector] public bool intransition = false;
void Awake() {
RenderSettings.ambientLight = outside;
}
void Update () {
if (intransit) {
RenderSettings.ambientLight = TheNewerCycleOfLifeAndDeath(nighttime);
}
}
private Color TheNewerCycleOfLifeAndDeath(bool daytime) {
Color lightingNow = RenderSettings.ambientLight;
if (daytime) {
if (lightningNow == outside) {
intransition = false;
nighttime = false;
return lightningNow;
}
return Color.Lerp(lightningNow, outside, Time.fixedDeltaTime * .5f);
}
else {
if (lightningNow == inside) {
intransition = false;
nighttime = true;
return lightningNow;
}
return Color.Lerp(lightningNow, inside, Time.fixedDeltaTime * .5f);
}
}
}
the trigger parent is this:
the tuerwaechterin (german for doorkeeper) script looks like this:
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class Tuerwaechterin : NetworkBehaviour {
public enum doorposition {
inner,
outer,
somethingelse,
}
private WakeUp zzz;
[HideInInspector] public bool goingInside = false;
[HideInInspector] public bool goingOutside = false;
[HideInInspector] public doorPos _doorPos;
void Awake() {
zzz = FindObjectOfType<WakeUp>();
_doorPos = doorposition.somethingelse;
}
public void light (bool night) {
zzz.intransition = true;
zzz.nighttime = night;
}
}
and all childs of that trigger parent are those invisible plane meshes acting as triggers:
tuerwaechterkinder (doorkeeper childs) script is this:
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class Tuerwaechterkinder : NetworkBehaviour {
[SerializeField] private Tuerwaechterin.doorposition state;
private Tuerwaechterin mama;
void Awake() {
mama = GetComponentInParent<Tuerwaechterin>();
}
void OnTriggerEnter (Collider other) {
if (other.tag != "Player") { return; }
if (state == Tuerwaechterin.doorposition.outer) { mama.goingInside = true; }
if (state == Tuerwaechterin.doorposition.inner) { mama.goingOutside = true; }
mama._doorPos = (mama._doorPos == Tuerwaechterin.doorposition.somethingelse) ? state : mama._doorPos;
if (mama.goingInside && mama.goingOutside) {
bool nighttime = (mama._doorPos == Tuerwaechterin.doorposition.outer) ? false : true;
mama.light(nighttime);
}
}
void OnTriggerStay (Collider other) {
if (other.tag != "Player") { return; }
}
void OnTriggerExit (Collider other) {
if (other.tag != "Player") { return; }
if (state == Tuerwaechterin.doorposition.outer) { mama.goingInside = false; }
if (state == Tuerwaechterin.doorposition.inner) { mama.goingOutside = false; }
if (!mama.goingInside && !mama.goingOutside) {
mama._doorPos = Tuerwaechterin.doorposition.somethingelse;
}
}
}
////////////
All in all i use confusing var titles i think and the code might be a “little” messy, i dont know, i’m auto didact. But i think the problem is somewhere else not necessarily in the trigger logic (which is working fine if you play solo).
Maybe it doenst need extend NetworkBehaviour at all?
Thanks for everyone who takes the time to get into this <3