Пример #1
0
    internal void SetControllerNumber(int number)
    {
        controllerNumber    = number;
        horizontalAxis      = "J" + controllerNumber + "Horizontal";
        verticalAxis        = "J" + controllerNumber + "Vertical";
        horizontalRightAxis = "J" + controllerNumber + "RightHorizontal";
        verticalRightAxis   = "J" + controllerNumber + "RightVertical";
        aButton             = "J" + controllerNumber + "A";
        xButton             = "J" + controllerNumber + "X";
        rightTriggerButton  = "J" + controllerNumber + "RightTrigger";
        startButton         = "J" + controllerNumber + "Start";

        // Set all controls
        GameObject PCBinding = GameObject.Find("PCBinding");
        ControllerPlayerBinding cpBinding = PCBinding.GetComponent <ControllerPlayerBinding>();

        Crosshair player_tank_crosshair_script = player_tank_crosshair.GetComponent <Crosshair>();

        if (cpBinding.getControllerBinding(tank_number) == 5)
        {
            isKeyboard = true;
        }
        player_tank_crosshair_script.SetCrosshairControls(horizontalRightAxis, verticalRightAxis, isKeyboard);

        player_tank_gun_script = player_tank_gun.GetComponent <PlayerGun>();
        print(player_tank_gun_script);
        player_tank_gun_script.SetGunController(xButton, rightTriggerButton);
    }
Пример #2
0
    // Start is called before the first frame update
    void Start()
    {
        isDead      = false;
        gameManager = FindObjectOfType(typeof(GameManager)) as GameManager;
        healthMax   = 100; // temp
        health      = healthMax;
        GameObject PCBinding = GameObject.Find("PCBinding");
        ControllerPlayerBinding cpBinding = PCBinding.GetComponent <ControllerPlayerBinding>();

        SetControllerNumber(cpBinding.getControllerBinding(tank_number));
        rb             = GetComponent <Rigidbody2D>();
        rb.constraints = RigidbodyConstraints2D.FreezeRotation;
        groundmap      = GameObject.Find("GroundGrid").GetComponent <Tilemap>();
    }
Пример #3
0
    void spawnPlayersFromLobby(ControllerPlayerBinding playerControllerBinding)
    {
        PlayerSpawnArray = GameObject.FindGameObjectsWithTag("PlayerSpawn"); // Find all spawnpoints and put them in an array
        player_spawned   = new bool[PlayerSpawnArray.Length];                // Array

        for (int i = 0; i < 4; i++)
        {
            if (playerControllerBinding.getControllerBinding(i + 1) != 0 && PlayerSpawnArray.Length > 0)
            {
                // If not enough spawnpoints for players return to the main menu
                if (PlayerSpawnArray.Length <= playingPlayers)
                {
                    Debug.Log("PlayerSpawnArray length is too short for the amount of players. (1)");
                    SceneManager.LoadScene("MenuScene");
                }
                else
                {
                    playingPlayers++;

                    // Create GameObjects
                    GameObject tank;
                    GameObject tank_crosshair;

                    // Get random spawn spot
                    int spawn_spot = RandomPlayerSpawn();
                    if (spawn_spot == -1)
                    {
                        Debug.Log("Couldn't get free spawn_spot. (1) Level index: " + currentLevelIndex);
                        SceneManager.LoadScene("MenuScene");
                    }

                    // Spawn crosshair and tank on player spawn
                    tank_crosshair = Instantiate(crosshairs[i], PlayerSpawnArray[spawn_spot].transform.position, Quaternion.identity);
                    tank           = Instantiate(tanks[i], PlayerSpawnArray[spawn_spot].transform.position, Quaternion.identity);

                    allplayers[i] = tank;

                    tank.GetComponent <PlayerController>().SetCrosshair(tank_crosshair);
                    tank.GetComponent <PlayerController>().SetHealthBar(health_bars[i]);
                    //tank.GetComponent<PlayerController>().SendPlayerInfo(player_info);
                }
            }
            else
            {
                health_bars[i].SetActive(false);
            }
        }

        // If not enough players joined return to the main menu
        if (playingPlayers < 2)
        {
            Debug.Log("Not enough players joined (less than 2)");
            SceneManager.LoadScene("MenuScene");
        }

        // Destroy all Spawns
        for (int i = 0; i < PlayerSpawnArray.Length; i++)
        {
            Destroy(PlayerSpawnArray[i]);
        }
    }