Advertisement

How to properly exit this if statement (c#)

Started by May 05, 2020 09:59 PM
2 comments, last by Tom Sloper 4 years, 6 months ago

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}

pxl999666 said:
I'm very new to this would really appreciate some help as to what i'm doing wrong.

pxl999666 said:
How to properly exit this if statement (c#)

pxl999666 said:
speed *= 0;

You want us to teach you the basics of programming? Seriously?

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Advertisement

This is not a Game Design question. I am moving it (by the time you read it, “I have moved it”) to a more appropriate forum. The Game Design forum is not for just anything and everything game-related.

-- Tom Sloper -- sloperama.com

This topic is closed to new replies.

Advertisement