Hi there I have a script I am currently having a difficulty with. Basically the script changes the intensity of the directional light in my scene.
The script works fine for the person who hosts the game but doesn’t work for the people who connect to the hosts game.
I have a variable
level
This variable changes and I want to change the light intensity with it.
This is the script I have written:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class dayNightCycle : NetworkBehaviour { //changes day and night based on the wavelevel SpawnManager_waveLevel.cs script
Light light;
float fadeTime = 1f;
[SyncVar(hook = "OnLightAmountChange")]
float lightAmout = 0f;
SpawnManager_waveLevel level;
public override void OnStartLocalPlayer()
{
light = GetComponentInChildren<Light>();
level = GetComponent<SpawnManager_waveLevel>();
light.intensity = lightAmout;
}
// Update is called once per frame
void Update () {
changeLight();
}
void changeLight()
{
if (isLocalPlayer)
{
if (level.waveCounter == 1)
{
lightAmout = 0.03f;
light.intensity = Mathf.Lerp(light.intensity, lightAmout, fadeTime * Time.deltaTime);
}
else
{
lightAmout = 1f;
light.intensity = Mathf.Lerp(light.intensity, lightAmout, fadeTime * Time.deltaTime);
}
}
}
void OnLightAmountChange(float amount)
{
lightAmout = amount;
changeLight();
}
}