void Update() { if (!canMove || gameStateDataScriptRef.GetSceneState() != GameStateScript.SceneState.INGAME) { return; // If the player can't move or isn't on GameStateScript.cs INGAME mode, then the following code shouldn't be executed. } if (input.getInput("Horizontal") == 0 && input.getInput("Vertical") == 0) { state = PlayerState.STANDING; } else { state = PlayerState.WALKING; if (input.getInput("Run") != 0) { state = PlayerState.RUNNING; } } //Check for a double input of: W, A, S, D, and if so, apply runModeActive true if (input.wasDoubleClicked("doubleClickD")) { state = PlayerState.RUNNING; } else if (input.wasDoubleClicked("doubleClickA")) { state = PlayerState.RUNNING; } else if (input.wasDoubleClicked("doubleClickW")) { state = PlayerState.RUNNING; } else if (input.wasDoubleClicked("doubleClickS")) { state = PlayerState.RUNNING; } if (state == PlayerState.RUNNING) //The player should walk, run mode is inactive { speed += runSpeed * Time.deltaTime * 2f; if (speed > runSpeed) { speed = runSpeed; } } else if (state == PlayerState.WALKING) //Run mode is active, apply run speed { speed += walkSpeed * Time.deltaTime * 2f; if (speed > walkSpeed) { speed = walkSpeed; } } else if (state == PlayerState.STANDING) { speed = 0; } //print("State: " + state + ", Speed: " + speed); //Basic movement system: moveDirection.x = input.getInput("Horizontal") * speed; // The player's x movement is the Horizontal Input (0-1) * speed. moveDirection.z = input.getInput("Vertical") * speed; // The player's y movement is the Vertical Input (0-1) * speed. AnimatorUpdate(); }
void FixedUpdate() { if (gameStateDataScriptRef.GetSceneState() == GameStateScript.SceneState.INGAME) //This update section only works if we're INGAME: { //print(input.getInput("Pause")); //Pause input: if (input.getInput("Pause") != 0) { gameStateDataScriptRef.PauseGame(!gameStateDataScriptRef.gamePaused); gameStateDataScriptRef.SetSceneState(GameStateScript.SceneState.OPTIONS); } pressedBaseInteraction = input.isPressed("BaseInteraction"); /// PASSIVE INTERACTION (Sphere Light) Collider[] hitColliders = Physics.OverlapSphere(CylindricLight.transform.position, GetComponent <PlayerLight>().lightSphere.range - 3); //(Sphere center, Radius) int tmp = 0; for (int i = 0; i < hitColliders.Length; i++) { if (hitColliders[i].isTrigger) { if (hitColliders[i].gameObject.CompareTag("PlayerLight")) { continue; } switch (hitColliders[i].gameObject.tag) { case "LightOrb": if (input.isPressed("LightMax")) { hitColliders[i].GetComponent <LightOrb>().ChargeOrb(Color.white, amount); //Attempt to charge the light orb if we are expanding the player light sphere radius (Default white from player white ray) } else if (input.isPressed("BaseInteraction")) { hitColliders[i].GetComponent <LightOrb>().SubtractFromOrb(); //Attempt to subtract energy from the light orb if we press Q } break; case "BlackInsect": BlackInsect(hitColliders[i]); break; case "Mirror": //if (pressedBaseInteraction != 0 && prevBaseInteraction == 0) { FindObjectOfType<CameraScript>().setFocus(hitColliders[i].gameObject); } //if (pressedBaseInteraction && !prevBaseInteraction) { hitColliders[i].GetComponentInParent<MirrorRotateController>().Toggle(); } break; case "OpticalFiber": // Make closest node work (switching reverse or not): hitColliders[i].GetComponentInParent <OpticalFiber>().SetClosestNode(transform); // Charge optical fiber: if (input.isPressed("LightMax")) { hitColliders[i].GetComponent <OpticalFiber_Node>().AddCharge(amount); } //else if (input.isPressed("BaseInteraction")) hitColliders[i].GetComponentInParent<OpticalFiber>().StartPlayerMode(transform); break; default: break; } tmp++; } } prevBaseInteraction = pressedBaseInteraction; } /* * else if (gameStateDataScriptRef.GetSceneState() == GameStateScript.SceneState.FILESELECT) //This update section only works if we're in FILESELECT: * { ++timer; * * if (input.getInput("Horizontal") != 0 && timer > selectDelay) * { * highlightedFile[0] = !highlightedFile[0]; * timer = 0; * } * else if (input.getInput("Vertical") != 0 && timer > selectDelay) * { * highlightedFile[1] = !highlightedFile[1]; * timer = 0; * } * * boatOutlinesOff(); * * //FILE SELECTOR: * if (highlightedFile[0] == false && highlightedFile[1] == false) * { * highlightedFilenum = 1; * FileSelectorBoat1.GetComponentInChildren<cakeslice.Outline>().enabled = true; * } * else if (highlightedFile[0] == true && highlightedFile[1] == false) * { * highlightedFilenum = 2; * FileSelectorBoat2.GetComponentInChildren<cakeslice.Outline>().enabled = true; * } * else if (highlightedFile[0] == false && highlightedFile[1] == true) * { * highlightedFilenum = 3; * FileSelectorBoat3.GetComponentInChildren<cakeslice.Outline>().enabled = true; * } * if (highlightedFile[0] == true && highlightedFile[1] == true) * { * highlightedFilenum = 4; * FileSelectorBoat4.GetComponentInChildren<cakeslice.Outline>().enabled = true; * } * * //INSERT LOAD SELECTED FILE HERE: * if (input.getInput("Submit") != 0) * { * //Provisional stuff for now: * boatOutlinesOff(); * gameStateDataScriptRef.SetSceneState(GameStateScript.SceneState.INGAME); * * transform.position = BaseWorldSpawnRef.transform.position; * } * }*/ }
// Update is called once per frame void Update() { if (gameStateDataScriptRef.GetSceneState() == GameStateScript.SceneState.INGAME) //This update section only works if we're INGAME: { if (input.getInput("LightSwitch") != 0 && prevLightAxis == 0 && canUseLight) { if (lightMode == LightMode.NEAR) { lightMode = LightMode.FAR; lightCylinderAngle = 0; } else if (lightMode == LightMode.MAX) { lightMode = LightMode.FAR; lightCylinderAngle = 0; } else if (lightMode == LightMode.FAR) { lightMode = LightMode.NEAR; } //print(lightMode); } prevLightAxis = input.getInput("LightSwitch"); mousePos = input.getMousePos(); if (input.isPressed("LightMax") && canUseLight) { if (lightMode == LightMode.NEAR || lightMode == LightMode.MAX) { lightMode = LightMode.MAX; } } else if (lightMode != LightMode.FAR) { lightMode = LightMode.NEAR; } switch (lightMode) { case LightMode.NEAR: lightSphere.range = Lerp(defaultLightSphereRange, lerpSpeed, lightSphere.range); //Light Orb radius to it's default range at LerpSpeed lightCylinder.transform.localScale = new Vector3(cylinderRadius, cylinderRadius, Lerp(defaultLightCylinderScale, 2f, lightCylinder.transform.localScale.z)); //Light cylinder back to 0 length if (lightCylinder.transform.localScale.z == 0) { lightCylinder.SetActive(false); } //Cilinder activity off since we are on near mode break; case LightMode.MAX: GetComponent <Player>().health -= healthDrainAmmount; //Decrease player health for doing this action lightSphere.range += expandingLightSpeed; //Expand the light on input at expansion speed if (lightSphere.range > maxExpandingLight) { lightSphere.range = maxExpandingLight; } //Light orb expansion limit break; case LightMode.FAR: GetComponent <Player>().health -= healthDrainAmmount; //Decrease player health for being in this mode lightCylinder.SetActive(true); lightSphere.range = Lerp(lightSphereRangeInFarMode, lerpSpeed, lightSphere.range); RaycastHit tmpHit = GetComponent <PlayerInteraction>().getRayHit(); if (tmpHit.collider != null) // If something was hit: { //Check at what distance the intersection happened: float distCylPosHitPos = Vector3.Distance(GetComponent <PlayerInteraction>().getRayHit().point, lightCylinder.transform.position); if (distCylPosHitPos / 2 > maxLightCylinderScale) { lightCylinder.transform.localScale = new Vector3(cylinderRadius, cylinderRadius, maxLightCylinderScale); } else { lightCylinder.transform.localScale = new Vector3(cylinderRadius, cylinderRadius, distCylPosHitPos / 2); } } else // Else, if nothing was hit: { lightCylinder.transform.localScale = new Vector3(cylinderRadius, cylinderRadius, Lerp(maxLightCylinderScale, 0.5f, lightCylinder.transform.localScale.z)); } LightMouseMovement(prevMousePos, mousePos); break; default: print("Error: wrong light mode."); break; } prevMousePos = mousePos; } }