コード例 #1
0
    void Awake()
    {
        _attackScript   = gameObject.GetComponent <SCR_PlayerAttack>();
        _inputScript    = GetComponent <SCR_PlayerInput>();
        uiManagerScript = GameObject.FindGameObjectWithTag("UIManager").GetComponent <SCR_UIManager>();

        //reset playerWeaponUI once for both players
        if (gameObject.tag == "Player1")
        {
            SCR_UIManager.instance.ResetWeaponSlots();
        }

        _gunInventory = new STR_GunInventory[numberOfWeapons];
        for (int i = 0; i < numberOfWeapons; i++)
        {
            _gunInventory[i].currentAmmo = 100;
        }

        _gunInventory[numberOfWeapons - 1].gunObject   = grenade;
        _gunInventory[numberOfWeapons - 1].currentAmmo = 5;


        Transform  gunPos      = _inputScript.gunPosition;
        GameObject infiniteGun = Instantiate(infinitePistolPrefab, gunPos.transform.position, new Quaternion(0, 180, 0, 0));

        infiniteGun.transform.parent   = gunPos;
        infiniteGun.transform.rotation = new Quaternion(0, 0, 0, 0);
        _gunInventory[2].gunObject     = infiniteGun;
        _gunInventory[2].currentAmmo   = 100;
        uiManagerScript.SetCurrentAmmoText(gameObject.tag, 0.0f, 0, 0, true);
        _currentWeaponInterface = (IWeapon)infiniteGun.GetComponent(typeof(IWeapon));
        _currentWeaponInterface.SetParent(gameObject);
        _attackScript.UpdateWeaponInterface(_currentWeaponInterface);
        _currentlySelectedWeapon     = 2;
        _inputScript.SpeedMultiplier = speedMultipler;
        GetComponent <SCR_PlayerHealth>().HealthMultiplier = healthMultiplier;
        weaponSwitchingSource = GetComponent <AudioSource>();
        uiManagerScript.SwitchGunImages(gameObject.tag, false, ThrowableType.FireGrenade, true);
        uiManagerScript.SwitchSelectedWeaponUI(gameObject.tag, _currentlySelectedWeapon);
        playerWorldSpaceUIScr = GetComponent <SCR_PlayerWorldSpaceUI>();

        MAX_TRG_SCL = GetComponent <SCR_PlayerAttack>().MAX_TRG_SCL;
    }
コード例 #2
0
    //co routine which will play out the level, spawning in the pooled enemies
    IEnumerator playLevel()
    {
        // Play the blimp spotlight animation if it exists
        if (blimpSpotlightPlayableDirector != null)
        {
            blimpSpotlightLight.gameObject.SetActive(true);
            blimpSpotlightPlayableDirector.Play();
        }

        while (selectedConfiguration.poolSize > 0 || enemyObjects.Count > 0)
        {
            if (SCR_Boss.instance.bossAttacking)
            {
                SCR_Boss.instance.BossAttack(false);
            }


            if (enemyObjects.Count < selectedConfiguration.maxSpawnSize && selectedConfiguration.poolSize > 0)
            {
                int rng = Random.Range(0, selectedConfiguration.poolSize);

                bool       pointChosen = false;
                int        nodeSpawn   = 0;
                GameObject currentNode = this.gameObject;
                while (!pointChosen)
                {
                    nodeSpawn   = Random.Range(0, spawnNodes.Count);
                    currentNode = spawnNodes[nodeSpawn];
                    if (!currentNode.GetComponent <SCR_SpiderPortal>().currentlySpawning)
                    {
                        pointChosen = true;
                    }
                    yield return(null);
                }
                currentNode.GetComponent <SCR_SpiderPortal>().OpenPortal(0.5f);
                GameObject spawn = Instantiate(returnEnemyPrefab(selectedConfiguration.ReturnPoolsType(rng)), currentNode.transform.position + (Vector3.down * 3), Quaternion.identity);
                spawn.transform.parent = transform;
                enemyObjects.Add(spawn);
                AssignTypes();
                IEnemy currentEnemyInterface = (IEnemy)spawn.GetComponent(typeof(IEnemy));
                currentEnemyInterface.SetRoomManager(this.gameObject);
                if (buffEnemy != null)
                {
                    currentEnemyInterface.BuffEnemy(buffEnemy.GetComponent <SCR_BuffSpider>().returnBuffType());
                }
                float timer = Random.Range(2.5f, 4.0f);
                StartCoroutine(currentEnemyInterface.spawnEnemy(currentNode, timer));
            }
            yield return(null);
        }

        SCR_AudioManager.instance.Play("DoorOpen");
        for (int i = 0; i < enterTriggers.Count; i++)
        {
            IFightRoomTrigger current = enterTriggers[i].GetComponent <IFightRoomTrigger>();
            current.ClosePrimary(true, gateTimer);
        }

        if (buffEnemy != null)
        {
            buffEnemy.GetComponent <SCR_BuffSpider>().PowerDown();
        }
        SCR_AudioManager.instance.PlayWalkMusic();
        SCR_GameManager.instance.PlayerFighting = false;

        if (player1 & player2)
        {
            SCR_PlayerWorldSpaceUI player1WorldSpaceUIScr = player1.GetComponent <SCR_PlayerWorldSpaceUI>();
            SCR_PlayerWorldSpaceUI player2WorldSpaceUIScr = player2.GetComponent <SCR_PlayerWorldSpaceUI>();

            if (player1WorldSpaceUIScr)
            {
                player1WorldSpaceUIScr.HealPrompt(true);
            }

            if (player2WorldSpaceUIScr)
            {
                player2WorldSpaceUIScr.HealPrompt(true);
            }

            yield return(new WaitForSeconds(4.0f));

            if (player1WorldSpaceUIScr)
            {
                player1WorldSpaceUIScr.HealPrompt(false);
            }

            if (player2WorldSpaceUIScr)
            {
                player2WorldSpaceUIScr.HealPrompt(false);
            }
        }

        // Fade out the blimp light
        if (blimpSpotlightLight != null)
        {
            StartCoroutine(FadeOutBlimpSpotlight());
        }
    }
コード例 #3
0
    public bool Fire()
    {
        bool bulletFired = false;

        if (bulletTimer <= 0 && _currentClip > 0 && !isReloading)
        {
            RaycastHit hitCamera;

            Vector3 pointTowards = new Vector3();
            pointTowards = transform.position + (transform.right * 9999);
            Vector3 direction = _gunPosition.position + transform.right;
            direction.y = transform.position.y;
            direction   = direction - transform.position;



            if (Physics.Raycast(transform.position, direction.normalized, out hitCamera, Mathf.Infinity, hitDetectionLayerMask, QueryTriggerInteraction.Ignore))
            {
                pointTowards = hitCamera.point;
            }

            pointTowards = GetShotPosAfterSpread(pointTowards, _gunValues.ACCURACY);

            Shoot(pointTowards);

            if (!IsInfinitePistol)
            {
                _currentClip--;
            }

            if (_playerParent)
            {
                if (!IsInfinitePistol)
                {
                    SCR_UIManager.instance.SetCurrentAmmoText(_playerParent.tag, _currentClip, -1, _gunValues.CLIPSIZE);
                }
                else
                {
                    SCR_UIManager.instance.SetCurrentAmmoText(_playerParent.tag, _currentClip, -1, _gunValues.CLIPSIZE, true);
                }
            }

            bulletTimer = (1 / (_gunValues.RATEOFFIRE)) * 5.0f;
            currentMuzzle.SetActive(true);

            //currentMuzzle.transform.LookAt(pointTowards);
            //currentMuzzle.transform.Rotate(Vector3.up, -90.0f);

            Invoke("DeactivateMuzzleEffect", 0.1f);
            currentGunShotSource.pitch = Random.Range(lowerPitchValue, higherPitchValue);
            currentGunShotSource.PlayOneShot(RetreiveGunShot(), currentGunShotSource.volume);
            bulletFired = true;
        }

        if (bulletTimer <= 0 && _currentClip <= 0 && !isReloading)
        {
            int weaponSlot = 0;
            switch (_gunValues.SLOTTYPE)
            {
            case GunTypes.Primary: weaponSlot = 0; break;

            case GunTypes.Secondary: weaponSlot = 1; break;

            case GunTypes.Infinite: weaponSlot = 2; break;

            case GunTypes.Throwable: weaponSlot = 3; break;
            }

            if (!worldSpaceUIScript)
            {
                if (_playerParent)
                {
                    worldSpaceUIScript = _playerParent.GetComponent <SCR_PlayerWorldSpaceUI>();
                }
            }
            if (worldSpaceUIScript)
            {
                if (_playerParent.GetComponent <SCR_CharacterInventory>().GetAmmo(weaponSlot) > 0)
                {
                    if (!worldSpaceUIScript.bIsDisplayed)
                    {
                        worldSpaceUIScript.ShowReloadPrompt(true);
                    }
                }
            }
        }

        if (bulletTimer <= 0 && _currentClip <= 0 && !bulletFired)
        {
            currentGunShotSource.pitch = 1;
            currentGunShotSource.PlayOneShot(emptyMagazineClip);
            bulletTimer = (1 / (_gunValues.RATEOFFIRE)) * 5.0f;
        }

        return(bulletFired);
    }