🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to properly exit this if statement (c#)

Started by
2 comments, last by Tom Sloper 4 years, 2 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}
Advertisement

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.

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