void Start() { MHS.WaitRun(1, () => { MessageBoxController.instance.Build(new MessageBoxParams { Position = Vector2.zero, Text = "MessageBox Example\nThis is an example for the MessageBox system!" }); }); }
void Start() { MHS.WaitRun(.1f, () => { if (cineMode == CineModes.None) { cineMode = CineModes.Target; if (target == null) { target = GameObject.FindGameObjectWithTag("Player").transform; } } snapNextFrame = true; }); ProCamera2D.Instance.CenterOnTargets(); }
void Start() { MHS.WaitRun(1, () => { MessageBoxController.BuildMessages( "MessageBox Example\n" + "Press Fire1 to continue to the next message.", "You can use .Next() method to run something AFTER a\nset of messages." ).Next(() => { MHS.WaitRun(0.5f, () => { MessageBoxController.BuildMessages( new MessageBoxParams { Text = "MessageBoxExample\n" + "Each message can have it's own set of parameters! :)", Position = new Vector2(0, 2), Speed = 0 }, new MessageBoxParams { Text = "This one is much slower for example...", FadeTime = 1.6f, Speed = 25 } ); }); }); }); }
// the Update loop contains a very simple example of moving the character around and controlling the animation void Update() { if (movementMode == MovementModes.None) { return; } // Crawling /* * hit raycast looks above to see if anything above, just incase forced crouching is nessesary * if not crawling + is grounded, and either the hit raycast collides, or if the movement mode is not no interaction and the player presses down, is grounded and is not pressing left or right * Just added, check if anything below.. this helps with slopes... but may need some tweeking * then begin crouching */ RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.up, 1, LayerMask.GetMask("Default"), 0, 0); RaycastHit2D hitDown = Physics2D.Raycast(transform.position, Vector2.down, 0.6f, LayerMask.GetMask("Default"), 0, 0); if (movementMode != MovementModes.Crawling && _controller.isGrounded && hitDown.collider != null) { if ((hit.collider != null) || (movementMode != MovementModes.NoPlayerInteraction && _controller.isGrounded && Input.GetAxisRaw("Horizontal") == 0 && Input.GetAxisRaw("Vertical") == -1)) { movementMode = MovementModes.NoPlayerInteraction; startedCrouching = true; // Instant if forced if (hit.collider == null) { animator.ResetTrigger("LayDown"); animator.SetTrigger("LayDown"); } else { animator.ResetTrigger("LayDownInstant"); animator.SetTrigger("LayDownInstant"); } MHS.WaitRun(0.45f, () => { movementMode = MovementModes.Crawling; startedCrouching = false; }); } } if (movementMode == MovementModes.Normal || movementMode == MovementModes.NoPlayerInteraction) { if (_controller.isGrounded) { _velocity.y = 0; } if (movementMode != MovementModes.NoPlayerInteraction && Input.GetAxisRaw("Horizontal") == 1) { normalizedHorizontalSpeed = 1; directionFacing = 1; //if( _controller.isGrounded ) // _animator.Play( Animator.StringToHash( "Run" ) ); } else if (movementMode != MovementModes.NoPlayerInteraction && Input.GetAxisRaw("Horizontal") == -1) { directionFacing = -1; normalizedHorizontalSpeed = -1; //if( _controller.isGrounded ) // _animator.Play( Animator.StringToHash( "Run" ) ); } else { normalizedHorizontalSpeed = 0; //if( _controller.isGrounded ) // _animator.Play( Animator.StringToHash( "Idle" ) ); } // we can only jump whilst grounded if (movementMode != MovementModes.NoPlayerInteraction && _controller.isGrounded && Input.GetButtonDown("Jump")) { AudioManager.instance.PlaySFX("Jump"); _velocity.y = Mathf.Sqrt(jumpHeight * -gravity); MHS.RunFor(0.2f, i => { if (Input.GetButton("Jump")) { _velocity.y = Mathf.Sqrt(jumpHeight * -gravity); } }); } // apply horizontal speed smoothing it. dont really do this with Lerp. Use SmoothDamp or something that provides more control var smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping; // how fast do we change direction? _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * runSpeed, Time.deltaTime * smoothedMovementFactor); // apply gravity before moving _velocity.y += gravity * Time.deltaTime; // if holding down bump up our movement amount and turn off one way platform detection for a frame. // this lets us jump down through one way platforms if (_controller.isGrounded && Input.GetKey(KeyCode.DownArrow)) { _velocity.y *= 3f; _controller.ignoreOneWayPlatformsThisFrame = true; } // Do the moving _controller.move(_velocity * Time.deltaTime); } else if (movementMode == MovementModes.SwimmingSurface) { float yPosOffset = -0.05f; if (enteringWater) { if (!startSurfaceing) { _controller.move(_velocity * Time.deltaTime); } else { _velocity = new Vector3(_velocity.x, _velocity.y += 20 * Time.deltaTime, _velocity.z); _controller.move(_velocity * Time.deltaTime); } if (transform.position.y < topOfWater - 0.3f) { startSurfaceing = true; } if (startSurfaceing && transform.position.y >= topOfWater + yPosOffset) { startSurfaceing = false; paddleingRotation = 0; enteringWater = false; _velocity = new Vector3(_velocity.x, 0, _velocity.z); transform.position = new Vector3(transform.position.x, topOfWater + yPosOffset, transform.position.z); } } if (!enteringWater) { transform.position = new Vector3(transform.position.x, topOfWater + yPosOffset, transform.position.z); float rotateSpeed = 240; if (movementMode != MovementModes.NoPlayerInteraction && Input.GetAxisRaw("Horizontal") == 1) { if (paddleingRotation > 0) { paddleingRotation /= 4; } paddleingRotation -= Time.deltaTime * rotateSpeed; directionFacing = 1; normalizedHorizontalSpeed = 1; } else if (movementMode != MovementModes.NoPlayerInteraction && Input.GetAxisRaw("Horizontal") == -1) { if (paddleingRotation < 0) { paddleingRotation /= 4; } paddleingRotation += Time.deltaTime * rotateSpeed; directionFacing = -1; normalizedHorizontalSpeed = -1; } else { if (paddleingRotation < Time.deltaTime * rotateSpeed) { paddleingRotation += Time.deltaTime * rotateSpeed; } if (paddleingRotation > Time.deltaTime * rotateSpeed) { paddleingRotation -= Time.deltaTime * rotateSpeed; } normalizedHorizontalSpeed = 0; } paddleingRotation = Mathf.Clamp(paddleingRotation, -45f, 45f); transform.rotation = Quaternion.Euler(0, 0, paddleingRotation); var smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping; // how fast do we change direction? _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * runSpeed / 1.5f, Time.deltaTime * smoothedMovementFactor); _velocity.y = 0; if (Input.GetButtonDown("Jump")) { MugHeadStudios.MHS.RunFor(0.1f, i => { transform.rotation = Quaternion.Euler(0, 0, paddleingRotation * (1 - i)); }, () => { transform.rotation = Quaternion.identity; }); _velocity.y = Mathf.Sqrt(2f * jumpHeight * -gravity); movementMode = MovementModes.Normal; Splash(); } _controller.move(_velocity * Time.deltaTime); } } else if (movementMode == MovementModes.Crawling) { _velocity.y -= 15 * Time.deltaTime; if (Input.GetAxisRaw("Horizontal") == 1) { directionFacing = 1; _velocity.x = 2; } else if (Input.GetAxisRaw("Horizontal") == -1) { directionFacing = -1; _velocity.x = -2; } else { _velocity.x = 0; } _controller.move(_velocity * Time.deltaTime); hitDown = Physics2D.Raycast(transform.position, Vector2.down, 0.6f, LayerMask.GetMask("Default"), 0, 0); if (Input.GetAxisRaw("Vertical") != -1 || hitDown.collider == null) { // Coming up from crouch, check above head first hit = Physics2D.Raycast(transform.position, Vector2.up, 1, LayerMask.GetMask("Default"), 0, 0); if (hit.collider == null) { movementMode = MovementModes.NoPlayerInteraction; MHS.WaitRun(0.4f, () => { movementMode = MovementModes.Normal; }); } } } // grab our current _velocity to use as a base for all calculations _velocity = _controller.velocity; // Animation animator.SetFloat("Running", (_controller.isGrounded && movementMode == MovementModes.Normal && Input.GetAxisRaw("Horizontal") != 0) ? 1 : 0); animator.SetBool("IsGrounded", _controller.isGrounded); animator.SetBool("IsPaddleing", (movementMode == MovementModes.SwimmingSurface)); animator.SetBool("IsCrawling", (startedCrouching || movementMode == MovementModes.Crawling)); animator.SetBool("CrawlingMoving", (movementMode == MovementModes.Crawling && Mathf.Abs(_velocity.x) > 0)); animator.SetBool("PaddleingSwimming", (movementMode == MovementModes.SwimmingSurface && Input.GetAxisRaw("Horizontal") != 0)); // Direction if (directionFacing == 1) { transform.localScale = new Vector3(1, transform.localScale.y, transform.localScale.z); } else if (directionFacing == -1) { transform.localScale = new Vector3(-1, transform.localScale.y, transform.localScale.z); } }
void Start() { player = Global.GetPlayer().gameObject; // If intro sequence is false if (!Global.gameData.forestIntroSequence) { MHSFader.instance.preventAutomaticFadeIn = true; player.GetComponent <Player>().playerGraphic.SetActive(false); player.GetComponent <PlayerMovement>().movementMode = PlayerMovement.MovementModes.None; CineTarget.instance.cineMode = CineTarget.CineModes.Position; targetStartMarker = CineTarget.instance.transform.position; ProCamera2D.Instance.CenterOnTargets(); MHSFader.FadeOut(0); MHS.WaitRun(3, () => { MHSFader.FadeIn(3); Vector2 targetEndMarker = new Vector2(0, 3); MHS.WaitRun(4, () => { MHSTools.MoveEntitySmooth(CineTarget.instance.transform, new Vector2(0, 4), 6, () => { MHS.WaitRun(2, () => { MessageBoxController.BuildMessages( "Huh, I don't remember sleeping here..." ).Next(() => { player.GetComponent <PlayerMovement>().movementMode = PlayerMovement.MovementModes.NoPlayerInteraction; player.GetComponent <Player>().playerGraphic.SetActive(true); player.transform.position = new Vector2(0, 6.5f); MHS.RunUntil(() => player.GetComponent <Prime31.CharacterController2D>().isGrounded, null, () => { GameObject.Instantiate(smokeBurstUp, player.transform.position + new Vector3(0, -0.4f), Quaternion.identity); AudioManager.instance.PlaySFX("Thump"); player.GetComponent <Player>().playerGraphic.GetComponent <Animator>().SetTrigger("FallFlat"); ProCamera2D.Instance.GetComponent <ProCamera2DShake>().Shake(1f, new Vector2(5f, 5f), 10, 0.1f, -1, new Vector3(5, 5, 10), 0.5f, false); MHS.WaitRun(2, () => { MessageBoxController.BuildMessages( "... OUCH" ).Next(() => { MHS.WaitRun(0.5f, () => { AudioManager.instance.PlayMusic(Global.instance.defaultMusic); MessageBoxController.BuildMessages( new MessageBoxParams { Text = "I better take a look around..." } ).Next(() => { player.GetComponent <Player>().playerGraphic.GetComponent <Animator>().SetTrigger("StandUpDizzy"); MHS.WaitRun(4f, () => { player.GetComponent <PlayerMovement>().movementMode = PlayerMovement.MovementModes.Normal; CineTarget.instance.cineMode = CineTarget.CineModes.Target; CineTarget.instance.target = player.transform; // Save Global.gameData.forestIntroSequence = true; Global.Save(); }); }); }); }); }); }); }); }); }); }); }); } // If intro sequence is true else { } }