Exemplo n.º 1
0
    //SHOULD EQUIP HANDS
    public void ThrowWeapon()
    {
        if (currentWeaponInstance == null)
        {
            return;
        }

        throwWeaponSFX.Play();

        isReloading = false;
        gameObject.GetComponent <PlayerShoot>().SetIsMidReload(false);
        isSpinning = false;

        Util.SetLayerRecursively(currentWeaponInstance, LayerMask.NameToLayer("Default"));
        currentWeaponInstance.layer = LayerMask.NameToLayer("Default");
        currentWeaponInstance.tag   = "Player Weapon";
        currentComponents.WeaponDropped();
        currentWeaponInstance.transform.SetParent(null);

        //NEW STUFF
        currentWeaponInstance.transform.localScale = new Vector3(1, 1, 1);

        Vector3 _throwDirection = weaponHolder.transform.forward.normalized;

        _throwDirection *= throwForce;
        currentComponents.rb.AddForce(_throwDirection, ForceMode.Force);

        currentWeapon         = null;
        shootPoint            = null;
        currentComponents     = null;
        currentWeaponInstance = null;
    }
Exemplo n.º 2
0
    public void EquipWeapon(GameObject _playerWeapon)
    {
        if (currentWeaponInstance != null)
        {
            ThrowWeapon();
            throwWeaponSFX.Stop();
        }

        reloadSFX.Play();

        //So the new weapon can move into position
        weaponIsAttatched = false;

        gameObject.GetComponent <PlayerShoot>().RemoteSetCanShoot(false);

        currentWeaponInstance = _playerWeapon;
        Util.SetLayerRecursively(currentWeaponInstance, LayerMask.NameToLayer("Weapon"));
        currentWeaponInstance.tag = "Untagged";

        currentWeapon = _playerWeapon.GetComponent <WeaponComponents>().playerWeaponInformation.GetWeaponInfo();

        currentWeaponInstance.transform.SetParent(weaponHolder);

        //NEW STUFF
        currentWeaponInstance.transform.localScale = new Vector3(1, 1, 1);

        currentComponents = currentWeaponInstance.GetComponent <WeaponComponents>();
        if (currentComponents == null)
        {
            Debug.LogError("No WeaponGraphics component on the weapon object " + currentWeaponInstance.name);
        }

        currentComponents.WeaponPickedUp();

        shootPoint = currentComponents.shootPoint.transform;

        Util.SetLayerRecursively(currentWeaponInstance, LayerMask.NameToLayer(weaponLayerName));
    }
Exemplo n.º 3
0
    private void Shoot()
    {
        currentAmmo--;
        playerUIScript.SetCurrentAmmo(currentAmmo.ToString());

        //Ray _direction;
        RaycastHit _hit;

        WeaponComponents _currentComponents = weaponManager.GetCurrentComponents();
        Transform        _shootPoint        = weaponManager.GetShootPoint();

        //Ray shot out of player bc gun does not point at the crosshair
        if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out _hit, weaponManager.GetCurrentWeapon().range, shootMask))
        {
            //Makes a game object where the raycast hits
            //                  MIGHT BE DANGEROUS \/
            GameObject _hitPoint = Instantiate(gameObject, _hit.point, Quaternion.LookRotation(_hit.normal));

            //Makes a particle effect on the barrel of the gun
            GameObject _shotEffect = Instantiate(_currentComponents.shotEffectPrefab, _shootPoint.position, _shootPoint.rotation);

            //Makes a laser beam
            GameObject _lazerBeam = Instantiate(_currentComponents.lazerPrefab, _shootPoint.position, _shootPoint.rotation);

            //Makes lazer go between gun shoot point and the object the ray hit
            _lazerBeam.GetComponent <LineRenderer>().SetPosition(0, _shootPoint.position);
            _lazerBeam.GetComponent <LineRenderer>().SetPosition(1, _hit.point);

            //Makes a particle effect at the hit point
            GameObject _hitEffect = Instantiate(_currentComponents.lazerHitPrefab, _hitPoint.transform.position, _hitPoint.transform.rotation);

            //Destroys relevent objects
            Destroy(_lazerBeam, _currentComponents.lazerDuration);
            Destroy(_hitEffect, _currentComponents.hitEffectDuration);
            Destroy(_shotEffect, _currentComponents.shotEffectDuration);
            Destroy(_hitPoint);

            //MAKE LAZERS INTERACT WITH THINGS
            if (_hit.collider.CompareTag("Player Weapon"))
            {
                _hit.collider.GetComponent <Rigidbody>().AddForceAtPosition(-_hit.normal * currentWeapon.lazerForce, _hit.point, ForceMode.Force);
            }
            else if (_hit.collider.CompareTag("Explosive Environment"))
            {
                GameObject _explosion = Instantiate(barrelExplosionPrefab, _hit.collider.gameObject.transform.position, _hit.collider.gameObject.transform.rotation);
                Util.SetTagRecursively(_explosion, "Player Explosion");
                Destroy(_hit.collider.gameObject);
                Destroy(_explosion, barrelExplosionDuration);
                playerUIScript.PlayHitMarker();
            }
            else if (_hit.collider.CompareTag("Enemy"))
            {
                _hit.collider.GetComponent <UniversalTurretBehaviors>().TakeDamage(currentWeapon.damage);
                playerUIScript.PlayHitMarker();
            }
        }
        else
        {
            //Makes a particle effect on the barrel of the gun
            GameObject _shotEffect = Instantiate(_currentComponents.shotEffectPrefab, _shootPoint.position, _shootPoint.rotation);

            //Makes a laser beam
            GameObject _lazerBeam = Instantiate(_currentComponents.lazerPrefab, _shootPoint.position, _shootPoint.rotation);

            //Makes lazer go between gun shoot point and the object the ray hit
            _lazerBeam.GetComponent <LineRenderer>().SetPosition(0, _shootPoint.position);
            _lazerBeam.GetComponent <LineRenderer>().SetPosition(1, playerCamera.transform.position + (playerCamera.transform.forward.normalized * currentWeapon.range));

            Destroy(_lazerBeam, _currentComponents.lazerDuration);
            Destroy(_shotEffect, _currentComponents.shotEffectDuration);
        }
    }