Beispiel #1
0
    private void Update()
    {
        if (currentBlock)
        {
            // Right and left
            if (Input.GetButtonDown("Horizontal"))
            {
                if (!BlockRight())
                {
                    if (Input.GetAxis("Horizontal") > 0)
                    {
                        transform.position += new Vector3(1, 0, 0);
                        currentDelay        = totalDelay;
                    }
                }
                if (!BlockLeft())
                {
                    if (Input.GetAxis("Horizontal") < 0)
                    {
                        transform.position += new Vector3(-1, 0, 0);
                        currentDelay        = totalDelay;
                    }
                }
            }

            if (Input.GetButtonDown("Jump"))
            {
                // Space for fast fall action
                while (!BlockBeneath())
                {
                    transform.position += new Vector3(0, -1, 0);
                }
            }

            if (!BlockBeneath())
            {
                // Up and down
                if (Input.GetButtonDown("Vertical"))
                {
                    if (Input.GetAxis("Vertical") > 0)
                    {
                        // Check if can rotate
                        CheckRotation();
                        transform.RotateAround(pivotPoint.position, Vector3.forward, 90);
                        currentDelay = totalDelay;
                    }
                    if (Input.GetAxis("Vertical") < 0)
                    {
                        transform.position += new Vector3(0, -1, 0);
                    }
                }


                fallDelay -= Time.deltaTime;

                if (fallDelay < 0)
                {
                    fallDelay = fallSpeed;
                    if (!BlockBeneath())
                    {
                        transform.position += new Vector3(0, -1, 0);
                    }
                }
            }
            else
            {
                currentDelay -= Time.deltaTime;

                if (currentDelay < 0)
                {
                    if (!blockSpawner.blockPlaced)
                    {
                        // Make sure block is aligned properly
                        transform.position = new Vector3(Mathf.Round(transform.position.x), Mathf.Round(transform.position.y), Mathf.Round(transform.position.z));

                        blockManager.AddSolidBlock(transform);

                        currentBlock = false;

                        // Ready the block spawner to send next block
                        blockSpawner.blockPlaced = true;
                    }
                }
            }
        }
    }