현재 멀티 플레이에서 빛의 밝기를 변경하려고 할 때 문제가 있습니다.광도 변경 Unity 멀티 플레이어
게임을 시작한 사람, 호스트의 광도가 미세하게 변경됩니다. 그러나 호스트에 연결하는 사람들은 빛의 강도가 변하지 않습니다.
[SyncVar]를 사용하여 광도를 변경하려고하지만 호스트에 연결 한 플레이어가 광도 변화를 전혀 보지 못합니다. 여기에 내 코드가있다 :
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();
}
}
내 문제는 빛의 강도가 한 플레이어, 호스트에 대해서만 변경된다는 것이다. 게임에 연결하는 모든 플레이어의 조명 강도를 변경하고 싶습니다. 어떤 제안이라도 환영합니다.
작성한 else 문에서 light 오브젝트를 찾을 수 없다는 것을 의미하는 OnStartLocalPlayer() 메소드가 있기 때문에이 방법이 작동하지 않을까 걱정된다. – arjwolf