void Update() { float x = Input.GetAxis("Horizontal"); //Input movement if (x > 0) { dir = 0.1F; } if (x < 0) { dir = -0.1F; } if (gameController.getfreezCam()) { dir = 0; } if (cam_transform.position.x > transform.position.x - (camWidth * distanceX_CamToPlayer) && dir < 0) //Right { cam_transform.position += new Vector3(camSpeed * dir, 0, 0); } if (cam_transform.position.x < transform.position.x + (camWidth * distanceX_CamToPlayer) && dir > 0) //Left { cam_transform.position += new Vector3(camSpeed * dir, 0, 0); } }
private void Update() { float x = Input.GetAxis("Horizontal"); //Input movement //Swap sprite and can't move when enter on ice or hide ability if (x > 0 && !blockDirectionIce && !gameController.getfreezCam()) { transform.localScale = new Vector3(1, transform.localScale.y, transform.localScale.z); directionIce = false; stopped = false; } else if (x < 0 && !blockDirectionIce && !gameController.getfreezCam()) { transform.localScale = new Vector3(-1, transform.localScale.y, transform.localScale.z); directionIce = true; stopped = false; } //Hide condition else if (speed == 0) { stopped = true; } //RockForm activation try { if (Input.GetKey(KeyCode.Space) && stopped && !ice) { //Change state gameController.setfreezeCamera(true); gameController.setrockState(true); eyesClosed = true; } else { gameController.setfreezeCamera(false); gameController.setrockState(false); eyesClosed = false; } } catch (Exception e) { print(e); } finally { } //Close eyes form activation try { if (Input.GetKey(KeyCode.Q) && stopped && !ice) { gameController.setfreezeCamera(true); gameController.sethideState(true); eyesClosed = true; } else { gameController.sethideState(false); } } catch (Exception e) { print(e); } finally { } //Jump activation jump = (Input.GetAxis("Jump") > 0); //devuelve true cuando se está saltando, sino, no se devuelve nada if (!jump) { jumpPressed = false; } try //Movement { if (grounded) { speed = (x * maxSpeed) * (moveReduction); running = (x * sprintSpeed + speed) * (moveReduction); } } catch (Exception e) { print("SpeedPlayer"); print(e); } try //Try to invoke damage functions (InvokeRepeatings) { if (insideFire) { if (!invokeIsCalled) { InvokeRepeating("fireDamageTiming", 0f, damageTime); } } if (insideBrambles) { if (!invokeIsCalled) { InvokeRepeating("bramblesDamageTiming", 0f, damageTime); invokeIsCalled = true; } } } catch (Exception e) { print("Damage Functions"); print(e); } finally { if (insideFire || insideBrambles) { invokeIsCalled = true; } } try //haunted condition { if (gameController.getbeingHunted() && !huntedState) { moveReduction += beingHuntedSpeed; print(moveReduction); huntedState = true; } else if (!gameController.getbeingHunted() && huntedState) { moveReduction -= beingHuntedSpeed; print(moveReduction); huntedState = false; } } catch (Exception e) { print("BeingHunted"); print(e); } finally { } anim.SetFloat("speed", Mathf.Abs(x)); //Run animation anim.SetBool("grounded", grounded); //Jump animation anim.SetBool("hidestate", gameController.getrockState()); //Hide animation animator.SetBool("eyes", eyesClosed); //Closed eyes animation anim.SetBool("eyestate", gameController.gethideState()); }