Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Server : MonoBehaviour {
- public bool is_started = false;
- public int num_connections = 30;
- public int server_port = 5551;
- public int server_start_time;
- public int toolbarInt = 0;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- print ("Delta Time"+ Time.fixedTime);
- //print(Time.time);
- }
- void OnGUI()
- {
- StartAction();
- ServerStatus();
- }
- void StartAction()
- {
- if(is_started == false)
- {
- if(GUI.Button(new Rect(10,50,150,30),"Start Server"))
- {
- Network.InitializeServer(num_connections,server_port,false);
- server_start_time = (int)Network.time;
- is_started = true;
- }
- }else{
- if(GUI.Button(new Rect(10,50,150,30),"STOP Server"))
- {
- Network.Disconnect();
- is_started = false;
- }
- }
- }
- void ServerStatus()
- {
- if(is_started == false){
- return ;
- }
- double serverLifeTime = Network.time - server_start_time;
- GUI.Label(new Rect(200,50,200,30),"Max ppls: "+ Network.maxConnections+"/"+Network.connections.Length);
- GUI.Label(new Rect(200,100,200,30),"Server Time: "+serverLifeTime.ToString("F0"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement