// Use this for initialization
 void Start()
 {
     if (!Statici.inGioco)
         return;
     datiPersonaggio = GetComponent<DatiPersonaggio>();
     if (Statici.multigiocatoreOn)
     {
         gestoreCanvasNetowork = GameObject.Find("ManagerCanvasMultiplayer").GetComponent<GestoreCanvasNetwork>();
         managerNetwork = GameObject.Find("ManagerNetwork").GetComponent<ManagerNetwork>();
     }
 }
    // Use this for initialization
    private void Start()
    {
        if (!Statici.multigiocatoreOn)
            return;
        TimeManager.Instance.Init();
        Application.runInBackground = true;
        punteggi.text = "";
        punteggi.gameObject.SetActive(false);

        gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
        gestoreCanvasNetwork = GameObject.Find("ManagerCanvasMultiplayer").GetComponent<GestoreCanvasNetwork>();
        me = this;
        minimappa = GameObject.Find("Minimappa").GetComponent<Minimappa>();
        if (!SmartFoxConnection.NonNulla)
        {
            SceneManager.LoadScene("ScenaZero");
            return;
        }
        sfs = SmartFoxConnection.Connection;
        sfs.ThreadSafeMode = true;
        sfs.AddEventListener(SFSEvent.OBJECT_MESSAGE, OnObjectMessage);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.USER_EXIT_ROOM, OnUserExitRoom);
        sfs.AddEventListener(SFSEvent.USER_ENTER_ROOM, OnUserEnterRoom);
        sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);
        sfs.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);

        SpawnaPlayerLocale();
    }
    private void Start()
    {
        transform_m = GetComponent<Transform>();

        navMeshAgent = GetComponent<NavMeshAgent>();
        if (navMeshAgent == null)
        {
            navMeshAgent = gameObject.AddComponent<NavMeshAgent>();
            navMeshAgent.height = 2f;
            navMeshAgent.stoppingDistance = 1f;
        }
        navMeshAgent.enabled = true;

        rigidBody = GetComponent<Rigidbody>();
        if (rigidBody == null)
        {
            rigidBody = gameObject.AddComponent<Rigidbody>();
            rigidBody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
        }
        rigidBody.isKinematic = true;

        ev_Audio = GetComponent<EventoAudio>();
        if (ev_Audio == null)
            ev_Audio = gameObject.AddComponent<EventoAudio>();

        audioZona = GetComponent<AudioZona>();
        if (audioZona == null)
            audioZona = gameObject.AddComponent<AudioZona>();

        animatore = GetComponent<Animator>();
        capsula = GetComponent<CapsuleCollider>();
        altezzaCapsula = capsula.height;
        capsulaCentro = new Vector3(0.0f, capsula.center.y, 0.0f);
        IsPointAndClick = true;
        layerAlberi = ~layerAlberi;
        switchVivoMorto = GetComponent<SwitchVivoMorto>();
        if (!Statici.inGioco)
            return;
        DatiPersonaggio = GetComponent<DatiPersonaggio>();

        if (!Statici.multigiocatoreOn)
        {
            Statici.RegistraDatiPersonaggio(DatiPersonaggio);
            //se all'inizio della partita si ritrova a 0 di vita, gli do 1 di vita così non nasce morto.
            if (DatiPersonaggio.Vita <= 0f)
            {
                DatiPersonaggio.Vita = 1f;
                SalvaDatiVita();
            }
        }
        else
        {

            managerNetwork = GameObject.Find("ManagerNetwork").GetComponent<ManagerNetwork>();
            gestoreCanvas = GameObject.Find("ManagerCanvasMultiplayer").GetComponent<GestoreCanvasNetwork>();
        }
    }