Professional Documents
Culture Documents
Collections;
using System.Collections.Generic;
using UnityEngine;
chargeTimer = chargeCooldown;
}
void Update()
{
anim_NPC.SetFloat("Speed", Mathf.Abs(rb_NPC.velocity.x));
HitPlayer();
WalkToPlayer();
}
void HitPlayer()
{
Vector2 center = new Vector2(transform.position.x + collider_NPC.offset.x,
transform.position.y + collider_NPC.offset.y); // Get the center of the boss
Collider2D hitPlayer = Physics2D.OverlapBox(center, collider_NPC.size, 0, 1
<< Player.layer); // Check if the boss touches the player
void WalkToPlayer()
{
float speed = walkSpeed; // Set Boss's
speed.
didChargeHit = false;
charging = true;
}
void ContinueCharge()
{
float speed = chargeSpeed * chargeDirection; // Set chargeSpeed to
negative (Left) or positive (Right)
anim_NPC.SetTrigger("Attack");
if(attackSound)
{
attackSound.Play();
}
}
private void OnCollisionExit2D(Collision2D collision) // When the boss leaves
the wall, enable charge.
{
if (collision.collider.tag == "BossStun")
{
disableCharge = false;
}
}
anim_NPC.SetBool("Stunned", true);
}
chargeTimer = chargeCooldown; // Reset the charge timer.
}
}
}