Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (!controlsEnabled)
        {
            return;
        }
        float yAxis = Input.GetAxis("Horizontal");

        if (yAxisInverted)
        {
            yAxis = -yAxis;
        }
        submarine.Accelerate(Input.GetAxis("Vertical") * accelerationSpeed * Time.deltaTime);
        submarine.Rotate(yAxis * rotationSpeed * Time.deltaTime);

        float delay        = 10f / attackSpeed;
        var   readyToShoot = Time.time - shot > delay;

        crosshair.ReadyToShoot = readyToShoot;

        if (readyToShoot && (Input.GetMouseButton(0) || Input.GetKey(KeyCode.Space)))
        {
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }
            if (weapon != null)
            {
                weapon.Shoot(transform, submarine.GetRotation(), damage);
                SoundPlayer.main.PlaySound(GameSoundType.TorpedoShoot);
                shot = Time.time;
            }
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        submarine.Accelerate(Input.GetAxis("Vertical") * accelerationSpeed * Time.deltaTime);
        submarine.Rotate(Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime);

        if (Input.GetMouseButtonDown(0))
        {
            if (weapon != null)
            {
                weapon.Shoot(transform, submarine.GetRotation());
            }
        }
    }