public void PlayStep() { if (IsGrounded()) { AudioLibrary.Play(AudioName.Footstep); } }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { enemy = animator.GetComponent <Enemy>(); rb = animator.GetComponent <Rigidbody2D>(); float dir = enemy.facingRight ? 1 : -1; rb.AddForce(new Vector2(dir * AttackForce, 0)); AudioLibrary.Play(AudioName.EnemySlash); }
/// <summary> /// When damage is taken, actors flash red. /// All actors will recieve a knockback effect from the damage recieved /// </summary> /// <param name="damageVal">Amount of damage recieved</param> protected virtual void RegisterDamage(int damageVal) { AudioLibrary.Play(AudioName.ActorHit); if (!hasSpriteMesh) { StartCoroutine(FlashRed()); } else { smc.FlashRed(hitTimePeriod); } }
/// <summary> /// Enemies have a certain amount of health and will die when health reaches 0. /// Hope is also restored when enemy is hit in its vulnerable state. /// </summary> /// <param name="damageVal">Amount of Damage recieved</param> protected override void RegisterDamage(int damageVal) { base.RegisterDamage(damageVal); health -= damageVal; if (isVulnerable) { RaiseHope(); } if (health <= 0) { AudioLibrary.Play(AudioName.EnemyDefeated); GameManager.s.RaiseKillCount(); Destroy(gameObject); } }
/// <summary> /// /// </summary> /// <param name="collision"></param> private void OnTriggerEnter2D(Collider2D collision) { GameObject other = collision.gameObject; if (other.GetComponent <Enemy>() != null) { if (Mathf.Abs(rb.velocity.x) == 1) { if (HopeManager.GetInstance().state == HopeState.High) { AudioLibrary.Play(AudioName.CrowdCheer); Camera.main.gameObject.GetComponent <CameraMovement>().ZoomCamera(); HopeManager.GetInstance().Hope -= 1; } } } }
private void RecieveDamage(GameObject other) { AnimatorStateInfo asi = other.GetComponent <Animator>().GetNextAnimatorStateInfo(0); if (asi.IsName("Attack") || asi.IsName("Idle")) { RegisterDamage(5); HopeManager.GetInstance().Hope += -2; AudioLibrary.Play(AudioName.CrowdGasp); } else { RegisterDamage(5); HopeManager.GetInstance().Hope += -1; } Knockback(transform.position - other.transform.position); }
protected override void OnTalk(AudioLibrary audioLibrary) { audioLibrary.Play("sweet-cat"); }
// Update is called once per frame void Update() { if (Time.timeScale != 0) { horizontal = Input.GetAxis("Horizontal"); vertical = Input.GetAxis("Vertical"); if (horizontal != 0) { Move(); } else { anim.SetBool("isMoving", false); } if (Input.GetButtonDown("Jump")) { if (IsGrounded()) { jumpTime = Time.time; anim.SetBool("jumpCharge", true); } } if (Input.GetButtonUp("Jump")) { if (IsGrounded()) { if (Time.time - jumpTime <= jumpTimeThreshold) { rb.AddForce(Vector2.up * jumpForce); AudioLibrary.Play(AudioName.LowJump); } else { rb.AddForce(Vector2.up * jumpForce * longJumpMultiplier); AudioLibrary.Play(AudioName.HighJump); } jumpTime = float.MaxValue; anim.SetBool("jumpCharge", false); } } if (rangedAttackTime + rangedAttackCooldown < Time.time && rangedAttackedRecently) { rangedAttackedRecently = false; } if (!anim.GetCurrentAnimatorStateInfo(1).IsName("Slash")) { if (Input.GetButtonDown("Slash")) { Slash(1f); rangedAttackedRecently = false; } if (Input.GetButtonDown("Slash2")) { if (rangedAttackedRecently) { GameManager.s.PopUpRangedNotification(); AudioLibrary.Play(AudioName.CrowdBoo); HopeManager.GetInstance().Hope -= 1; } rangedAttackedRecently = true; rangedAttackTime = Time.time; Slash(slashSpeed); } } } }
/// <summary> /// Fires a Slash from player based on speed and direction of movement. /// </summary> void Slash(float speed) { anim.SetTrigger("Slash"); GameObject go = Instantiate(Resources.Load <GameObject>("Prefabs/Slash")); Vector2 dir = Vector2.right; Slash slash = go.GetComponent <Slash>(); if (speed == 1) { slash.slashType = SlashType.Melee; go.transform.parent = tr; } else { slash.slashType = SlashType.Ranged; } go.transform.position = tr.position; if (horizontal == 0 && vertical == 0) { if (facingRight) { dir = Vector2.right; } else { dir = Vector2.left; } } else if (vertical != 0) { dir = new Vector2(0, vertical / (vertical == 0 ? 1 : Mathf.Abs(vertical))); } else { dir = new Vector2( horizontal / (horizontal == 0 ? 1 : Mathf.Abs(horizontal)), 0); } if (slash.slashType == SlashType.Ranged) { slash.damage = 1; AudioLibrary.Play(AudioName.PlayerSlash); } else { switch (HopeManager.GetInstance().state) { case HopeState.Low: slash.damage = 0; AudioLibrary.Play(AudioName.PlayerSlash); break; case HopeState.Normal: slash.damage = 5; AudioLibrary.Play(AudioName.PlayerSlash); break; case HopeState.High: slash.damage = 20; AudioLibrary.Play(AudioName.PlayerHighSlash); break; } } slash.SetRotationAndMove(dir * speed); }