Exemplo n.º 1
0
        private void Update()
        {
            Shader.SetGlobalVector("_PlayerPos", transform.position);

            if (currentHealth <= 0 || !canMove)
            {
                return;
            }
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                gamePaused ^= true; //hah, inverted!
                if (gamePaused)
                {
                    Message <PauseGame> .Raise(new PauseGame());
                }
                else
                {
                    Message <ContinueGame> .Raise(new ContinueGame());
                }
            }
            if (gamePaused)
            {
                return;
            }
            //movement input
            movementInput.x = Input.GetAxisRaw(horizontalInput);
            movementInput.y = Input.GetAxisRaw(verticalInput);
            movementInput.Normalize();

            //mouse position -> direction
            Vector2 mp = cam.ScreenToWorldPoint(Input.mousePosition);

            mouseDir     = (mp - body.position).normalized;
            transform.up = mouseDir;

            //firing bullets.
            if (Input.GetButton(fire) && Time.time - lastShotTime >= attackRate)
            {
                ProjectilePool.GetPoolObject().Init(projectile, gameObject);
                lastShotTime = Time.time;
            }
            if (secondaryAmmo > 0)
            {
                if (Input.GetButton(secondaryFire) && Time.time - lastSecondaryShot >= attackRate)
                {
                    ProjectilePool.GetPoolObject().Init(secondaryProjectile, gameObject);
                    lastSecondaryShot = Time.time;
                    secondaryAmmo--;
                }
            }
        }
Exemplo n.º 2
0
 void Shoot()
 {
     if (settings.movePattern == MovementType.Strafe && !inStrafeDistance) //strafe should only shoot while in their distance.
     {
         return;
     }
     if (dist > settings.attackRange) //out of range
     {
         return;
     }
     if (Time.time - lastShotTime >= settings.attackRate)
     {
         ProjectilePool.GetPoolObject().Init(settings.projectile, gameObject);
         lastShotTime = Time.time;
     }
 }