コード例 #1
0
ファイル: Movement.cs プロジェクト: dchmak/Split-Screen
    private void Update()
    {
        direction = new Vector3(Input.GetAxisRaw(horizontalAxis), Input.GetAxisRaw(verticalAxis), 0).normalized;
        Vector3 velocity = (blink && blinkTimer < blinkTime) ? direction * blinkSpeed * Time.deltaTime : direction * normalSpeed * Time.deltaTime;

        transform.position += velocity;

        if (blinkCooldownTimer == 0 && Input.GetButtonDown(blinkButton) && !blink)
        {
            print("Blink!");

            // blink particle effect
            if (blinkEffect != null)
            {
                ParticleSystem.ShapeModule shape = blinkEffect.shape;
                shape.rotation = new Vector3(Vector2.SignedAngle(direction, Vector2.right) + 180, 90, 0);
                blinkEffect.Play();

                shaker.CameraShaker(blinkEffect.main.duration, shakiness, Time.deltaTime);
            }

            blink = true;
        }

        //Debug.DrawRay(transform.position, direction, Color.red);
        if (Input.GetButtonDown(fireButton))
        {
            //print("Shoot!");

            if (gameManager.canShoot && direction != Vector3.zero)
            {
                shooter.Shoot(direction);
            }
        }

        if (blink)
        {
            blinkTimer += Time.deltaTime;
        }

        if (blinkTimer > blinkTime)
        {
            blink      = false;
            blinkTimer = 0f;

            blinkCooldownTimer = blinkCooldown;
        }

        if (blinkCooldownTimer > 0)
        {
            blinkCooldownTimer -= Time.deltaTime;
        }
        if (blinkCooldownTimer < 0)
        {
            blinkCooldownTimer = 0;
        }
    }
コード例 #2
0
    IEnumerator BossDeath()
    {
        _anim.enabled = false;                                             //stops the boss from moving
        _explosion1.SetActive(true);                                       //first explosion
        _cameraShake.CameraShaker(1);                                      //shakes a little
        yield return(new WaitForSeconds(1f));                              //waits a bit for the next boom

        _cameraShake.CameraShaker(2);                                      // more shaky
        _explosion2.SetActive(true);                                       //second explosion
        yield return(new WaitForSeconds(1f));                              //waits a bit for the next boom

        _cameraShake.CameraShaker(3);                                      // even more shaky
        _explosion3.SetActive(true);                                       //thrid explosion
        yield return(new WaitForSeconds(1f));                              //waits a bit for the next boom

        _cameraShake.CameraShaker(4);                                      // more shaky to the extreme!!!!
        Instantiate(_explosion4, transform.position, Quaternion.identity); // this spawns the last big explosion
        yield return(new WaitForSeconds(0.3f));                            // gives it a sec before...

        Destroy(this.gameObject);                                          //destroys the boss body

        yield break;
    }
コード例 #3
0
    private IEnumerator ShootCoroutine(Vector3 direction)
    {
        if (laser.IsPlaying())
        {
            yield break;
        }

        Assert.AreEqual(0, direction.z);

        float angle = Vector2.SignedAngle(direction, Vector2.right);

        laser.PlayBeam(angle);

        // charge
        //print("Charging...");
        yield return(new WaitForSeconds(laser.chargeTime));

        // shoot
        //print("Fire!");
        shaker.CameraShaker(laser.beamDuration, shakiness, Time.deltaTime);

        float timer = 0f;

        while (timer < laser.beamDuration)
        {
            // ray cast to see if hit
            RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, laser.range, ~(1 << gameObject.layer));
            if (hit)
            {
                //print("Hit " + hit.collider.name);
                HealthComponent health = hit.transform.GetComponent <HealthComponent>();
                health.TakeDamage(laser.damage);
            }

            timer += Time.deltaTime;
            yield return(null);
        }
    }
コード例 #4
0
 public void  ShakeCamera()
 {
     CameraShake.CreateShakeSetup(_cameraShakeConfig, Camera.main.gameObject);
     StartCoroutine(CameraShake.CameraShaker());
 }
コード例 #5
0
    public void Damage(bool Damage) // false = no damage, true = damage
    {
        if (_repairing)
        {
            StopCoroutine(RepairingIE);
            _repairing = false;
        }

        if (Damage)
        {
            if (_hasShield == true)
            {
                switch (_shieldCount)
                {
                case 1:     // last hit, remove shields
                    _shieldsRenderer.material.color = Color.white;
                    _shields.SetActive(false);
                    _hasShield = false;
                    break;

                case 2:    // taken 1 hit
                    _shieldCount--;
                    _shieldsRenderer.material.color = Color.red;
                    break;

                case 3:     //have fresh shield
                    _shieldCount--;
                    _shieldsRenderer.material.color = Color.green;
                    break;
                }
                return;
            }
            _lives--;
        }
        _uiManager.UpdateLives(_lives);

        switch (_lives)
        {
        case 0:
            _spawnManager.StopSpawning();
            _uiManager.GameOver();
            Instantiate(_playerDeath, transform.position, Quaternion.identity);
            _cameraShake.CameraShaker(3);
            //instaniate the death explosion
            Destroy(this.gameObject);
            break;

        case 1:
            _playerDamageRight.SetActive(true);
            if (Damage)
            {
                _cameraShake.CameraShaker(2);
            }
            break;

        case 2:
            _playerDamageLeft.SetActive(true);
            _playerDamageRight.SetActive(false);
            if (Damage)
            {
                _cameraShake.CameraShaker(1);
            }
            break;

        default:
            _playerDamageRight.SetActive(false);
            _playerDamageLeft.SetActive(false);
            break;
        }
    }