Exemple #1
0
    void RpcRespawn()
    {
        if (isLocalPlayer)
        {
            playerIsDead     = false;
            movement.enabled = true;

            mouseLook.ToggleRespawnCamera(false);
            playerUI.ShowRespawnUi(false);
            // Set the spawn point to origin as a default value
            Vector3 spawnPoint    = Vector3.zero;
            Vector3 spawnRotation = Vector3.zero;

            // If there is a spawn point array and the array is not empty, pick one at random
            if (spawnPoints != null && spawnPoints.Length > 0)
            {
                int randomIndex = Random.Range(0, spawnPoints.Length - 1);
                spawnPoint    = spawnPoints[randomIndex].transform.position;
                spawnRotation = spawnPoints[randomIndex].transform.rotation.eulerAngles;
                Debug.Log("Spawn rotation " + spawnRotation);
            }

            // Set the player’s position to the chosen spawn point
            transform.position = spawnPoint;
            mouseLook.SetRotation(spawnRotation);
            movement.getRigidBody().velocity = new Vector3(0, 0, 0);
            CmdSetWeapon(0);
            OnChangeAmmo(SyncListInt.Operation.OP_DIRTY, currentGunIndex);
        }
    }