Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (EEGManager.IsInitialized() && outline && raycastTimer.Finished)
        {
            raycastTimer.Reset();
            RaycastHit hit;
            Vector3    dir = ((EEGGameManager.Instance.player.transform.position + Vector3.up * 0.2f) - transform.position);
            if (Physics.Raycast(transform.position + (dir.normalized * 0.5f), dir, out hit, EEGGameManager.Instance.hearingDistance))
            {
                if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Wall"))
                {
                    foreach (MaterialSwitcher s in materialSwitchers)
                    {
                        s.SwitchToAlternative();
                    }
                }
                else
                {
                    foreach (MaterialSwitcher s in materialSwitchers)
                    {
                        s.SwitchToMain();
                    }
                }
            }
        }

        raycastTimer.Update(Time.deltaTime);
    }
Exemplo n.º 2
0
    public void Recoil()
    {
        Vector3 rotationAmount = Random.insideUnitSphere * RecoilMagnitude;

        dx = rotationAmount.x;
        dy = rotationAmount.y;
        recoilTimer.Reset();
    }
Exemplo n.º 3
0
    public void StartBlinking()
    {
        durationTimer.Reset();
        if (blinking)
        {
            return;
        }

        if (imageToToggle != null)
        {
            blinking = true;
            InvokeRepeating("ToggleState", 0, interval);
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (Status == Spo2GameStatus.Playing)
        {
            if (Input.GetKeyDown(KeyCode.P))
            {
                Status = Spo2GameStatus.Paused;
                return;
            }


            if (remainingZombies <= 0)
            {
                if (wave == waves.Count)
                {
                    Status = Spo2GameStatus.PlayerWins;
                    return;
                }

                wave += 1;
                SoundManager.Instance.PlayClip(newWaveClip);
                waveTimer.Reset();
                remainingZombies = waves [wave - 1];
                waveEnded        = true;
                spawnedZombies   = 0;

                if (healthCount == 0)
                {
                    healthCount = spawnItems(healthSpawnLocations, minAmmoSpawn, maxAmmoSpawn, ItemType.HEALTH);
                }
            }

            if (ammoCount == 0)
            {
                ammoCount = spawnItems(ammoSpawnLocations, minAmmoSpawn, maxAmmoSpawn, ItemType.AMMO);
            }

            if (waveEnded && waveTimer.Finished)
            {
                waveEnded = false;
                Spawn();
            }

            if (!waveEnded && spawnTimer.Finished && spawnedZombies < waves [wave - 1])
            {
                Spawn();
            }

            spawnTimer.Update(Time.deltaTime);
            waveTimer.Update(Time.deltaTime);

            if (player.health <= 0)
            {
                Status = Spo2GameStatus.GameOver;
            }
        }
        else if (Status == Spo2GameStatus.Paused)
        {
            if (Input.GetKeyDown(KeyCode.P))
            {
                Status = Spo2GameStatus.Playing;
                return;
            }
        }
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (health > 0 && currentTarget != null)
        {
            Vector3 dir = (player.transform.position - transform.position);

            if (patrolMode && !playerFound && player.enabled)
            {
                if (Agent.remainingDistance < 0.1)
                {
                    patrolIndex++;
                    patrolIndex  %= patrols.Count;
                    currentTarget = patrols [patrolIndex];
                }

                if (raycastTimer.Finished)
                {
                    raycastTimer.Reset();
                    RaycastHit hit;
                    Vector3    rayOrigin = transform.position;
                    dir.y = 0.2f;
                    float dot      = Vector3.Dot(transform.forward, dir);
                    float distance = Vector3.Distance(transform.position, player.transform.position);
                    if (distance <= maxViewingDistance && Physics.Raycast(rayOrigin, dir, out hit, maxViewingDistance))
                    {
                        if (dot >= 0 || distance <= hearingDistance)
                        {
                            FPSPlayer player = hit.collider.GetComponent <FPSPlayer> ();
                            if (player != null)
                            {
                                PlayerFound();
                            }
                        }
                    }
                }
            }
            else if (playerFound)
            {
                dir.y = 0.2f;
                float dot = Vector3.Dot(transform.forward, dir);
                if (!attacking && Vector3.Distance(player.transform.position, transform.position) <= (stoppingDistance * 1.2f) && dot >= 0)
                {
                    StartCoroutine(Attack());
                }
            }
            if (Agent.enabled)
            {
                Agent.destination = currentTarget.position;
            }

            if (animator.enabled)
            {
                animator.SetFloat("Speed", Agent.speed);
            }

            if (growlTimer.Finished && !AudioSrc.isPlaying)
            {
                growlTimer.Reset();
                AudioSrc.PlayOneShot(growlClip);
                AudioSrc.volume = 1;
            }

            growlTimer.Update(Time.deltaTime);
            raycastTimer.Update(Time.deltaTime);
        }
    }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (!started)
        {
            processorContainer = FindObjectOfType <ProcessorContainer> ();
            if ((processorContainer != null && processorContainer.processor != null))
            {
                EEGManager.Instance.Processor = processorContainer.processor;
                EEGManager.Instance.Trained   = true;
                Status = GameStatus.Playing;
            }
            else
            {
                Status = GameStatus.Training;
            }

            started = true;
        }

        switch (status)
        {
        case GameStatus.Playing:
            if (Input.GetKeyDown(KeyCode.P))
            {
                Status = GameStatus.Paused;
                return;
            }

            if (player.health <= 0)
            {
                Status = GameStatus.GameOver;
                return;
            }

            EyesStatus status = EEGManager.Instance.Status;

            if (status == EyesStatus.CLOSED)
            {
                if (previousStatus == EyesStatus.OPEN)
                {
                    visibilityOn = false;
                    foreach (OutlineObject visibleObject in activeObjects)
                    {
                        visibleObject.Outline = false;
                    }
                    inactiveObjects.UnionWith(activeObjects);
                    activeObjects.Clear();
                }

                visibilityTime += Time.deltaTime;

                if (checkingTimer.Finished)
                {
                    checkingTimer.Reset();
                    foreach (Bomb bomb in bombs)
                    {
                        float distance = Vector3.Distance(player.transform.position, bomb.transform.position);
                        if (distance <= hearingDistance)
                        {
                            if (!activeBombs.Contains(bomb))
                            {
                                bomb.PlayBeepSound();
                                activeBombs.Add(bomb);
                            }
                        }
                        else
                        {
                            if (activeBombs.Contains(bomb))
                            {
                                activeBombs.Remove(bomb);
                                bomb.StopPlaying();
                            }
                        }
                    }

                    foreach (OutlineObject inactiveObject in inactiveObjects)
                    {
                        float distance = Vector3.Distance(player.transform.position, inactiveObject.transform.position);
                        if (distance <= hearingDistance)
                        {
                            activeObjects.Add(inactiveObject);
                        }
                    }

                    inactiveObjects.RemoveWhere(x => activeObjects.Contains(x));
                }
            }
            else
            {
                foreach (Bomb bomb in activeBombs)
                {
                    bomb.StopPlaying();
                }
                activeBombs.Clear();

                if (previousStatus == EyesStatus.CLOSED)
                {
                    visibilityTimer = new CounterTimer(Mathf.Min(visibilityTime + EEGManager.Instance.minThreshold, maxVisibilityDuration));
                    foreach (OutlineObject activeObject in activeObjects)
                    {
                        activeObject.Outline = true;
                    }
                    visibilityOn = true;
                }
                else
                {
                    if (visibilityOn && visibilityTimer.Finished)
                    {
                        visibilityOn = false;
                        foreach (OutlineObject activeObject in activeObjects)
                        {
                            activeObject.Outline = false;
                        }
                        inactiveObjects.UnionWith(activeObjects);
                        activeObjects.Clear();
                    }
                }

                if (visibilityOn)
                {
                    visibilityTimer.Update(Time.deltaTime);
                }

                visibilityTime = 0;
            }

            previousStatus = status;
            checkingTimer.Update(Time.deltaTime);
            break;

        case GameStatus.Paused:
            if (Input.GetKeyDown(KeyCode.P))
            {
                Status = GameStatus.Playing;
                return;
            }
            break;

        case GameStatus.Training:
            if (Input.GetKey(KeyCode.K))
            {
                EEGManager.Instance.StopTraining();
            }
            break;

        default:

            break;
        }
    }
Exemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        coolDownTimer.Update(Time.deltaTime);
        reloadTimer.Update(Time.deltaTime);

        if (Input.GetKeyDown(KeyCode.L))
        {
            flashlight.enabled = !flashlight.enabled;
            MainAudioSource.PlayOneShot(flashlightClip);
        }

        if (Input.GetKeyDown(reloadKey) && reloadTimer.Finished)
        {
            if (remainingRounds >= 1)
            {
                gunAudioSource.PlayOneShot(ReloadClip);
                reloadTimer.Reset();
                int reloadCount = Mathf.Min(magSize - rounds, remainingRounds);
                rounds          += reloadCount;
                remainingRounds -= reloadCount;
            }
            else
            {
                gunAudioSource.PlayOneShot(GunEmptyClip);
            }
        }

        if (reloadTimer.Finished && coolDownTimer.Finished && Input.GetMouseButtonDown(0))
        {
            if (rounds <= 0)
            {
                gunAudioSource.PlayOneShot(GunEmptyClip);
            }
            else
            {
                Animator.SetTrigger("Fire");
                shellEffect.Play();
                coolDownTimer.Reset();
                gunAudioSource.PlayOneShot(GunShotClip);
                rounds--;
                LookManager.Instance.Recoil();
                Vector3 rayOrigin = FPSCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));

                RaycastHit hit;

                if (Physics.Raycast(rayOrigin, FPSCam.transform.forward, out hit, Range))
                {
                    HitBox hitBox = hit.collider.GetComponent <HitBox> ();
                    // If there was a health script attached
                    if (hitBox != null)
                    {
                        // Call the damage function of that script, passing in our gunDamage variable
                        hitBox.Hit(hit);
                    }
                    else
                    {
                        BombHitBox bombHitBox = hit.collider.GetComponent <BombHitBox> ();
                        if (bombHitBox != null)
                        {
                            Bomb bomb = bombHitBox.transform.parent.gameObject.GetComponent <Bomb> ();
                            bomb.Explode();
                        }
                    }
                }
            }
        }
    }