Guys so i am kind of a begginer to unity, i do know codding but i struggle with unity.
I have a character that was a move function:
float hDirection = Input.GetAxis("Horizontal");
anim.SetFloat("Speed", Mathf.Abs(hDirection));
if (hDirection < 0)
{
rotation.localScale = new Vector3(-1, 1, 1);
attackPoint.transform.position = new Vector3(this.transform.position.x - 1, attackPoint.position.y, this.transform.position.z);
}
else if (hDirection > 0)
{
rotation.localScale = new Vector3(1, 1, 1);
attackPoint.transform.position = new Vector3(this.transform.position.x + 1, attackPoint.position.y, this.transform.position.z);
}
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
transform.position += movement * Time.deltaTime * moveSpeed;
transform.rotation = Quaternion.LookRotation(Vector3.forward, transform.up);
And a attack function:
void Attack()
{
if (isGrounded)
{
if (Time.time >= nextAttackTime)
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
isAttacking = true;
//Attack animation
anim.SetTrigger("Attack");
//Detect enemies in range
Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);
//Damage enemies
foreach (Collider2D enemy in hitEnemies)
{
enemy.GetComponent<Enemy>().TakeDamage(attackDamage);
}
nextAttackTime = Time.time + 1f / attackRate;
}
}
}
}
I want my character not to move while attacking what can i do ?