private void ShootBullet()
    {
        if (lastShootTime_Bullet + shootDelay_Bullet > Time.time)
        {
            return;
        }

        //Rumble
        InputDevice device = InputDeviceManager.GetPlayerDevice(playerInput.GetPlayerIndex());

        RumbleManager.Instance.StartRumble(device, .1f, .15f, .015f);

        float      spreadOffset   = Random.Range(-currentSpread / 2f, currentSpread / 2f);
        Quaternion spreadRotation = firePoint.rotation * Quaternion.Euler(0f, spreadOffset, 0f);

        GameObject tempBullet = Instantiate(bulletPrefab, firePoint.position, spreadRotation, projectileContainer);
        Rigidbody  bulletRb   = tempBullet.GetComponent <Rigidbody>();


        bulletRb.AddForce(tempBullet.transform.forward * shootForce_Bullet);
        lastShootTime_Bullet = Time.time;

        playerAudioSource.PlayOneShot(shootClip_Bullet, shootClipScale_Bullet);
        SwitchToAR();
    }
    private void ShootRocket()
    {
        if (lastShootTime_Rocket + shootDelay_Rocket > Time.time)
        {
            return;
        }

        //Rumble
        InputDevice device = InputDeviceManager.GetPlayerDevice(playerInput.GetPlayerIndex());

        RumbleManager.Instance.StartRumble(device, .5f, .3f, .1f);

        GameObject tempRocket = Instantiate(rocketPrefab, firePoint.position, Quaternion.LookRotation(firePoint.forward), projectileContainer);
        Rigidbody  rocketRb   = tempRocket.GetComponent <Rigidbody>();

        rocketRb.AddForce(firePoint.forward * shootForce_Rocket);
        lastShootTime_Rocket = Time.time;

        playerAudioSource.PlayOneShot(shootClip_Rocket, shootClipScale_Rocket);
        SwitchToRocket();
    }
Exemple #3
0
    private void SpawnPlayers()
    {
        int playerCount = InputDeviceManager.GetCurrentPlayerCount();

        //If no current players, use the default
        if (playerCount == 0 && defaultPlayer != null)
        {
            int playerIndex = 0;
            if (Gamepad.current != null)
            {
                InputDeviceManager.AddPlayer(Gamepad.current.device);
            }

            defaultPlayer.GetComponent <PlayerInputController>().SetPlayerIndex(playerIndex);

            defaultPlayer.transform.position = playerSpawns[0].position;
        }
        else
        {
            if (defaultPlayer != null)
            {
                Destroy(defaultPlayer);
            }
            int maxPlayers = InputDeviceManager.GetMaxPlayerCount();
            for (int i = 0; i < maxPlayers; i++)
            {
                if (InputDeviceManager.GetPlayerDevice(i) != null)
                {
                    int        playerIndex = i;
                    GameObject tempPlayer  = PlayerInput.Instantiate(playerPrefab, playerIndex, "Gamepad", -1, InputDeviceManager.GetPlayerDevice(playerIndex)).gameObject;
                    tempPlayer.gameObject.GetComponent <PlayerInputController>().SetPlayerIndex(playerIndex);

                    Transform playerObj = tempPlayer.transform.root;
                    playerObj.position = playerSpawns[i].position;
                    playerObj.parent   = playerContainer;
                }
            }
        }
    }