예제 #1
0
    void RemovePlayer(int i)
    {
        Movement[] player = FindObjectsOfType <Movement>();

        if (player[i] != null)
        {
            if (player[i].playerInputID == 1)
            {
                playerSpawned1 = false;
            }
            if (player[i].playerInputID == 2)
            {
                playerSpawned2 = false;
            }
            if (player[i].playerInputID == 3)
            {
                playerSpawned3 = false;
            }
            if (player[i].playerInputID == 4)
            {
                playerSpawned4 = false;
            }
            if (player[i].playerInputID == 5)
            {
                playerSpawned5 = false;
            }
            if (player[i].playerInputID == 6)
            {
                playerSpawned6 = false;
            }

            players--;

            Destroy(player[i].gameObject);

            PlayersInSceneChanged?.Invoke();
        }
    }
예제 #2
0
    public void SpawnPlayer(int i)
    {
        if (spawnPoint == Vector3.zero)
        {
            Debug.LogWarning("No Spawnpoint in scene");
            spawnPoint = GameObject.FindGameObjectWithTag("Respawn").transform.position;
        }

        if (spawnPoint != Vector3.zero)
        {
            GameObject spawnedPlayer = Instantiate(playerPrefabs.GetPlayer(players), spawnPoint, Quaternion.identity);
            if (spawnEffect != null)
            {
                Instantiate(spawnEffect, spawnedPlayer.transform.position, Quaternion.identity);
            }
            Movement m = spawnedPlayer.GetComponent <Movement>();
            m.playerInputID = i;
            //m.playerID = players;

            players++;

            switch (i)
            {
            case 1:
                playerSpawned1 = true;
                m.horizontal   = InputManager.CustomInputs.P1Keyboard.horizontal;
                m.jump         = InputManager.CustomInputs.P1Keyboard.jump;
                m.crouch       = InputManager.CustomInputs.P1Keyboard.crouch;
                break;

            case 2:
                playerSpawned2 = true;
                m.horizontal   = InputManager.CustomInputs.P2Keyboard.horizontal;
                m.jump         = InputManager.CustomInputs.P2Keyboard.jump;
                m.crouch       = InputManager.CustomInputs.P2Keyboard.crouch;
                break;

            case 3:
                playerSpawned3 = true;
                m.horizontal   = InputManager.CustomInputs.P1.horizontal;
                m.jump         = InputManager.CustomInputs.P1.jump;
                m.crouch       = InputManager.CustomInputs.P1.crouch;
                break;

            case 4:
                playerSpawned4 = true;
                m.horizontal   = InputManager.CustomInputs.P2.horizontal;
                m.jump         = InputManager.CustomInputs.P2.jump;
                m.crouch       = InputManager.CustomInputs.P2.crouch;
                break;

            case 5:
                playerSpawned5 = true;
                m.horizontal   = InputManager.CustomInputs.P3.horizontal;
                m.jump         = InputManager.CustomInputs.P3.jump;
                m.crouch       = InputManager.CustomInputs.P3.crouch;
                break;

            case 6:
                playerSpawned6 = true;
                m.horizontal   = InputManager.CustomInputs.P4.horizontal;
                m.jump         = InputManager.CustomInputs.P4.jump;
                m.crouch       = InputManager.CustomInputs.P4.crouch;
                break;

            default:
                Debug.LogError("Inputs not assigned!");
                break;
            }

            PlayersInSceneChanged?.Invoke();
        }
    }