public void startRotatingForward()
    {
        // disable battery restrictions when in tutorial
        if (tutorialOn || BatterySystem.GetPower() > 0)
        {
            if (!tutorialOn)
            {
                BatterySystem.SubPower(1);
            }
            numXClicks++;
            RotateBehavior rotateBehavior = objectToRotate.GetComponent <RotateBehavior>();
            if (!rotateBehavior.rotating())
            {
                //rotate
                rotateBehavior.setRotatingForward(true);
                float targetRotation = rotateBehavior.getTargetRotation();

                objectToRotate.transform.Rotate(-targetRotation, 0, 0);
                rotateBehavior.setEndRotation(objectToRotate.transform.rotation);
                objectToRotate.transform.Rotate(targetRotation, 0, 0);
            }

            timerStart = true;
        }
    }
 // Checks battery, returns whether this rotation can happen. If it cannot, shows error.
 // This method will likely be deprecated now that battery power is controlled by rotation counter and timer
 bool CheckBattery()
 {
     // Check if we're in the standard game mode and have no power.
     if (BatterySystem.GetPower() == 0 && !controlsDisabled && !FuseEvent.runningJustConstructionMode)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemple #3
0
    void Update()
    {
        // Restarting game while in construction mode.
        // DEMO MODE ONLY.
        if (Input.GetKey(KeyCode.T) && Input.GetKey(KeyCode.R))
        {
            InventoryController.RestartGame();
        }


        // LookAts.
        Vector3 lookToward = mainCamera.transform.position;

        // X
        xGizmo.transform.LookAt(new Vector3(xGizmo.transform.position.x, lookToward.y, lookToward.z));
        Vector3 xTemp = xGizmo.transform.localEulerAngles;

        xTemp.z = 90;
        xGizmo.transform.localEulerAngles = xTemp;

        // Y
        yGizmo.transform.LookAt(new Vector3(lookToward.x, xGizmo.transform.position.y, lookToward.z));

        // Z
        zGizmo.transform.LookAt(new Vector3(lookToward.x, lookToward.y, xGizmo.transform.position.z));
        Vector3 zTemp = zGizmo.transform.localEulerAngles;

        zTemp.z = 90;
        zGizmo.transform.localEulerAngles = zTemp;


        // Raycasts.
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hitInfo = new RaycastHit();
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo) && (tutorialOn || BatterySystem.GetPower() > 0))
            {
                //Debug.Log(hitInfo.transform.name);
                switch (hitInfo.transform.name)
                {
                case "XUp":
                    xRots++;
                    if (Mathf.Approximately(xGizmo.transform.localEulerAngles.y, 180f))
                    {
                        StartCoroutine(Rotate(90f, 0f, 0f));
                    }
                    else
                    {
                        StartCoroutine(Rotate(-90f, 0f, 0f));
                    }
                    break;

                case "XDown":
                    xRots++;
                    if (Mathf.Approximately(xGizmo.transform.localEulerAngles.y, 180f))
                    {
                        StartCoroutine(Rotate(-90f, 0f, 0f));
                    }
                    else
                    {
                        StartCoroutine(Rotate(90f, 0f, 0f));
                    }
                    break;

                case "YLeft":
                    yRots++;
                    StartCoroutine(Rotate(0f, 90f, 0f));
                    break;

                case "YRight":
                    yRots++;
                    StartCoroutine(Rotate(0f, -90f, 0f));
                    break;

                case "ZUp":
                    zRots++;
                    if (Mathf.Approximately(zGizmo.transform.localEulerAngles.y, 270f))
                    {
                        StartCoroutine(Rotate(0f, 0f, -90f));
                    }
                    else
                    {
                        StartCoroutine(Rotate(0f, 0f, 90f));
                    }
                    break;

                case "ZDown":
                    zRots++;
                    if (Mathf.Approximately(zGizmo.transform.localEulerAngles.y, 270f))
                    {
                        StartCoroutine(Rotate(0f, 0f, 90f));
                    }
                    else
                    {
                        StartCoroutine(Rotate(0f, 0f, -90f));
                    }
                    break;

                default:
                    break;
                }
            }
        }
    }