I'm trying to get my enemy to detect my player using a Raycast, making him stop and perform an attack. I want to make the enemy resume his idle state once the Player is out of the ray's range. Right now if the enemy encounters the player, he stops, but the speed variable remains 0.
I'm very new to this would really appreciate some help as to what i'm doing wrong.
RaycastHit2D isPlayer = Physics2D.Raycast(playerdetector.position,direction, shootingrange);
if(isPlayer == true){
if(isPlayer.collider.CompareTag("Player")){
speed *= 0;
}else{
speed=-2}