void OnCollisionEnter2D(Collision2D col) { if (col.collider.tag == "Player") { if (s_CameraFollow != null) { s_CameraFollow.StartCoroutine(s_CameraFollow.CameraShake(0.15f, 0.4f)); } else if (s_CameraFollowStage2 != null) { s_CameraFollowStage2.StartCoroutine(s_CameraFollowStage2.CameraShake(0.15f, 0.4f)); } if (o_Player.transform.localScale == new Vector3(1, 1, 1)) { o_Player.transform.Rotate(0, 0, 20); } else if (o_Player.transform.localScale == new Vector3(-1, 1, 1)) { o_Player.transform.Rotate(0, 0, -20); } StartCoroutine(wait(0.5f)); } }
/* ------ Camera Movements ------ */ public void CameraShake(float intensity, float duration, bool fade) { if (cam == null) { Debug.Log("Error: Camera Perspective is not assigned"); return; } cam.CameraShake(intensity, duration, fade); }
void OnTriggerEnter2D(Collider2D col) { if (col.tag == "Player") { if (s_CameraFollow != null) { s_CameraFollow.StartCoroutine(s_CameraFollow.CameraShake(0.15f, 0.4f)); } else if (s_CameraFollowStage2 != null) { s_CameraFollowStage2.StartCoroutine(s_CameraFollowStage2.CameraShake(0.15f, 0.4f)); } StartCoroutine(wait(1f)); } }
void Jump() { if (/*IsGrounded ||*/ !JumpInput) { jumped = false; jumpCooldown.Reset(); } if (jumped) { jumpCooldown.CountDown(); } if (Input.GetKeyDown(KeyCode.Space) && IsGrounded) { pressed = true; } if (Input.GetKeyUp(KeyCode.Space)) { pressed = false; } if (IsGrounded && !triggered) { triggered = true; spent = false; StopCoroutine(T()); StartCoroutine(T(0.4f)); CameraFollow.CameraShake(); AudioController.PlayAudio(transform.position, audioClips.landingSound, 0.5f, 0.9f); } else if (!IsGrounded) { triggered = false; } if (!IsGrounded && pressed) { if (jumpCooldown.LowerThan(jumpCooldown.delay / 2f) && Stats.lightLevel > 0 && JumpInput) { Stats.LightLevels((-30f - (inLight ? 15f : 0f)) * Time.deltaTime); spent = true; } else { spent = false; } } if (!IsGrounded && !pressed && rb.velocity.y > 0 || !IsGrounded && jumpCooldown.TriggerReady(false) && rb.velocity.y > 0 || !IsGrounded && !spent && jumpCooldown.LowerThan(jumpCooldown.delay / 2f) && rb.velocity.y > 0) { Vector3 v = rb.velocity; v.y = Mathf.MoveTowards(v.y, 0, 35f * Time.deltaTime); rb.velocity = v; } if (rb.velocity.y < 0 && !IsGrounded) { rb.AddForce(Vector3.down * 19.81f, ForceMode.Acceleration); } if (IsGrounded) { rb.useGravity = false; } else { rb.useGravity = true; } rb.useGravity = !jumped || jumpCooldown.TriggerReady(false); if (IsGrounded && JumpInput && !jumpCooldown.TriggerReady(false) && pressed) { if (!jumped) { AudioController.PlayAudio(transform.position, audioClips.jumpSound, 0.7f, 1.5f); jumped = true; anim.SetTrigger("Jump"); } rb.velocity = new Vector2(rb.velocity.x, jumpForce); } else { if (jumped) { anim.ResetTrigger("Jump"); } } /*if (attacking) * { * return; * }*/ }