private void Update()
        {
            if (Input.GetMouseButtonDown(1))
            {
                blockRotation.Advance();
                newBlockFilter.transform.rotation =
                    Quaternion.AngleAxis(blockRotation.ToDegrees(), Vector3.up);
            }

            float rotationInput = (Input.GetKey(KeyCode.Q) ? -1f : 0f) +
                                  (Input.GetKey(KeyCode.E) ? 1f : 0f);

            float forwardsBackInput = (Input.GetKey(KeyCode.S) ? -1f : 0f) +
                                      (Input.GetKey(KeyCode.W) ? 1f : 0f);

            float strafeInput = (Input.GetKey(KeyCode.A) ? -1f : 0f) +
                                (Input.GetKey(KeyCode.D) ? 1f : 0f);

            cameraPivot.rotation *= Quaternion.AngleAxis(rotationInput * camRotateSpeed * Time.deltaTime, Vector3.up);

            transform.position += cameraPivot.forward * forwardsBackInput * camMoveSpeed * Time.deltaTime
                                  + cameraPivot.right * strafeInput * camMoveSpeed * Time.deltaTime;

            transform.position = new Vector3
            {
                x = Mathf.Clamp(transform.position.x, RangeX.start, RangeX.end),
                y = transform.position.y,
                z = Mathf.Clamp(transform.position.z, RangeZ.start, RangeZ.end)
            };
        }
Example #2
0
 /// <summary>
 /// Executes the command for block placement.
 /// </summary>
 public override void Execute()
 {
     base.Execute();
     // Block out the tiles that this block occupies.
     stageState.FillRegion(rect.x, rect.y, rect.width, rect.height);
     // Add the visual components to the GameObject.
     spawnedInstance.transform.position = atLocation;
     spawnedInstance.transform.rotation = Quaternion.AngleAxis(rotation.ToDegrees(), Vector3.up);
     spawnedInstance.AddComponent <MeshRenderer>().material =
         new Material(Shader.Find("Diffuse"));
     spawnedInstance.AddComponent <MeshFilter>().sharedMesh   = blockData.mesh;
     spawnedInstance.AddComponent <MeshCollider>().sharedMesh = blockData.mesh;
 }