コード例 #1
0
    private void FixedUpdate()
    {
        if (isInMiningState || UpgradesStation.IsShopOpen() || inventory.IsOpen())
        {
            return;
        }

        if (Input.GetKey(KeyCode.A))
        {
            if (!isDirLeft && !Input.GetKey(KeyCode.D))
            {
                SwitchDirection();
            }
            rb.AddForce(new Vector2(-forceSpeed * Time.fixedDeltaTime, 0f));
        }
        if (Input.GetKey(KeyCode.D))
        {
            if (isDirLeft && !Input.GetKey(KeyCode.A))
            {
                SwitchDirection();
            }
            rb.AddForce(new Vector2(forceSpeed * Time.fixedDeltaTime, 0f));
        }
        if (Input.GetKeyDown(KeyCode.W))
        {
            CameraShaker.Instance.StartShake(0.2f, 3, 0f);
        }
        if (!Input.GetKey(KeyCode.W)) // Just checking for Input.GetKeyUp(KeyCode.W) rarely misses a shake
        {
            thrusterSource.Stop();
            thrusterAnim.SetBool("isThrusting", false);
            foreach (CameraShakeInstance shake in CameraShaker.Instance.ShakeInstances)
            {
                shake.StartFadeOut(0f);
            }
            CameraShaker.Instance.ShakeInstances.Clear();
        }
        if (Input.GetKey(KeyCode.W))
        {
            isFlying = true;
            UseThruster();
            if (!thrusterSource.isPlaying)
            {
                thrusterSource.Play();
            }
            thrusterAnim.SetBool("isThrusting", true);
            rb.AddForce(new Vector2(0f, forceSpeed * Time.fixedDeltaTime * 0.8f));
        }

        // Clamp speed
        if (Mathf.Abs(rb.velocity.x) >= maxSpeed)
        {
            rb.velocity = new Vector2(rb.velocity.x > 0 ? maxSpeed : -maxSpeed, rb.velocity.y);
        }
        if (Mathf.Abs(rb.velocity.y) >= maxSpeed)
        {
            rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y > 0 ? maxSpeed : -maxSpeed);
        }
    }
コード例 #2
0
    private void Update()
    {
        if (UpgradesStation.IsShopOpen() || inventory.IsOpen())
        {
            return;
        }

        // Check for fuel consumption
        if (isInMiningState || Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))
        {
            fuelManager.DecreaseFuel(Time.deltaTime / 3);
        }

        if (!isFlying && IsTouchingGround() && (isInMiningState || rb.velocity.magnitude > 0.5f))
        {
            movingAnim.SetBool("isMoving", true);
        }
        else
        {
            movingAnim.SetBool("isMoving", false);
        }

        if (isFlying && IsTouchingGround())
        {
            isFlying = false;
            UseHorizontalDrill();
        }

        // Check for mining state
        if (!isInMiningState && !isFlying && rb.velocity.magnitude == 0)
        {
            // Get player tile position
            Vector2Int pos = new Vector2Int(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.y));

            // Get direction to see if player wants to mine
            if (Input.GetKey(KeyCode.A) && isDirLeft && GroundManager.ExistsTileInPosition(pos + new Vector2Int(-1, 0)))
            {
                StartMining(pos, Vector2Int.left);
            }
            if (Input.GetKey(KeyCode.D) && !isDirLeft && GroundManager.ExistsTileInPosition(pos + new Vector2Int(1, 0)))
            {
                StartMining(pos, Vector2Int.right);
            }
            if (Input.GetKey(KeyCode.S) && GroundManager.ExistsTileInPosition(pos + new Vector2Int(0, -1)))
            {
                StartMining(pos, Vector2Int.down);
            }
        }
    }
コード例 #3
0
 public void OnXUpgradesButtonListener()
 {
     UpgradesStation.SetShopState(false);
 }