Exemplo n.º 1
0
    /// <summary>
    /// The locally called shoot that calls the RPC shoot
    /// No need to always call the RPC shoot, better check some conditions first
    /// </summary>
    void Shoot()
    {
        //If the current weapon is the zero'th index, don't do anything
        if (currentWeapon != weaponList[0])
        {
            //If the CLIENT'S version have more bullets left. Note this is also getting checked on the server
            if (currentWeapon.bulletsPerClip > 0 && !isReloading)
            {
                //Wait between shots
                if (Time.time > nextShotTime)
                {
                    //set the next shot time
                    nextShotTime = Time.time + currentWeapon.timeBetweenShots;
                    //Find the points from the clients camera and send them to the server to calculate the shot from.
                    //On a fully server auth solution, the server would have a version of the camera and calculate the shot from that
                    Vector3 rayOrigin = np.PlayerCamera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));
                    Vector3 forward   = np.PlayerCamera.transform.forward;
                    //send the rpc
                    np.networkObject.SendRpc(PlayerBehavior.RPC_SHOOT, BeardedManStudios.Forge.Networking.Receivers.All, rayOrigin, forward);

                    //shake that cam'
                    camShake.DoCameraShake(currentWeapon.recoilAmount, 0.1f);
                    //viewmodel shooting animation
                    viewModelAnimator.SetTrigger("shoot");

                    //Use coroutine for the muzzle flash so we can toggle it for a single frame
                    if (viewModelMuzzleFlashCorountine != null)
                    {
                        StopCoroutine(viewModelMuzzleFlashCorountine);
                    }
                    viewModelMuzzleFlashCorountine = StartCoroutine(ShowViewModelMuzzle(currentWeapon.viewModelMuzzlePoint.transform.position));
                }
            }
        }
    }
    public void DecreaseEnemyAmount(int pointAmount)
    {
        StartCoroutine(cameraScript.DoCameraShake(.2f));
        EnemiesOnScreen--;
        audio.Play(); //play enemy death sound

        //COMBO STUFF
        comboCount++;
        Points += pointAmount * comboCount;
        timer   = 0;//give more time to kill more enemies
    }
Exemplo n.º 3
0
    private void OnCollisionEnter(Collision collision)
    {
        if (!playerHasFallenToPlanet)
        {
            fallParticles.Play();
            StartCoroutine(shake.DoCameraShake(.1f));

            audio.PlayOneShot(fallSound, fallVolume);
            playerHasFallenToPlanet = true;//only plays once

            foreach (TrailRenderer t in trails)
            {
                t.emitting = true;
            }
        }
    }
Exemplo n.º 4
0
    private void Update()
    {
        //If the attack cd is 0
        if (timeBetweenAttacks <= 0)
        {
            if (Input.GetButtonDown("BowAttack"))
            {
                if (!coroutineStarted)
                {
                    StartCoroutine(FireBow());
                }
            }

            else if (Input.GetButtonDown("FinalAttack"))
            {
                if (ableToUnleashFinal)
                {
                    //AUDIO do final attack sound
                    audio.PlayOneShot(startOfFinalAttack, startOfFinalAttackVolume); //Final attack sound attached directly to audio source so it can be stopped.
                    Instantiate(finalParticles, finalParticleSpawn.transform.position, Quaternion.identity);
                    StartCoroutine(FinalAttackSoundDelay());
                    timeBetweenAttacks = originalTimeBetweenAttacks;//sreset time
                    Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(finalAttackPosition.position, finalAttackRange, allEnemies);

                    for (int i = 0; i < enemiesToDamage.Length; i++)
                    {
                        enemiesToDamage[i].GetComponent <Enemy>().TakeDamage(finalDamage);
                        playerScript.AddEnergy(chargePerAttack);
                    }

                    StartCoroutine(cameraScript.DoCameraShake(.2f)); //HACk magic number

                    ableToUnleashFinal = false;                      //after you do the attack, you can't do it again right away
                    playerScript.AddEnergy(-100);                    //Sets bar back to 0 energy, figure out how to make this not a magic number
                }
            }
        }
        else
        {
            timeBetweenAttacks -= Time.deltaTime;
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// The RPC called when TakeDamage is called
    /// </summary>
    /// <param name="args"></param>
    private void RPCTakeDamage(RpcArgs args)
    {
        //Get the first argument
        int healthLeft = args.GetNext <int>();

        //set the health variable, as health is only subtracked from the server
        health = healthLeft;

        //call the take damage event
        if (OnPlayerTakeDamage != null)
        {
            OnPlayerTakeDamage();
        }

        //Do a lil' camera shake for impact
        ///if (np.networkObject.IsOwner)
        if (!np.networkObject.IsRemote)
        {
            camShake.DoCameraShake(1.0f, 0.1f);
        }

        //Get the rest of the arguments
        Vector3 hitPoint  = args.GetNext <Vector3>();
        Vector3 hitNormal = args.GetNext <Vector3>();

        //Spawn the blood particle. TODO: Do some object pooling here as it's not ideal to spawn a new particle each hit
        if (bloodImpactParticle != null)
        {
            if (hitNormal == Vector3.zero || hitPoint == Vector3.zero)
            {
                return;
            }
            var spawnedBloodParticle = Instantiate(bloodImpactParticle, hitPoint, Quaternion.FromToRotation(Vector3.forward, hitNormal));
            spawnedBloodParticle.Play();
            //Destory the particle again
            Destroy(spawnedBloodParticle, 2.0f);
        }
    }