Hi guys,
I’m using unity network with a dedicated server (no player is hosting).
I’m using command and rpc for a while but always with player objects, for the first time, I need to set up some kind of LevelManager. For what I understand so far, I need to instantiate it with a network identity component with NetworkServer.Spawn.
This manager is correctly registered in the network manager as a prefab.
Anyway, I just don’t get any debug clients side, the rpc function doesn’t seem to be called at all.Here is my code, anyone can point out the error ?
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using UnityEngine.Networking.NetworkSystem;
using System;
using System.Collections;
public class Timer : NetworkBehaviour
{
public int timeLeft;
public int gameDuration = 120;
public Text timeText;
// Use this for initialization
void OnEnable()
{
timeText=GameObject.FindGameObjectWithTag("LevelTimer").GetComponent<Text>();
timeLeft = gameDuration;
if (isServer)
{
RpcUpdateTime(timeLeft);
Countdown();
}
}
private IEnumerator Countdown()
{
while (timeLeft > 0)
{
timeLeft--;
RpcUpdateTime(timeLeft);
yield return new WaitForSeconds(1);
}
RpcTimeUp();
}
[ClientRpc]
void RpcUpdateTime(int time){
timeLeft = time;
timeText.text = timeLeft.ToString("0.00") + "s";
}
[ClientRpc]
void RpcTimeUp()
{
Debug.Log("Time's Up !");
}
}
Thanks u all !