2.5D enemy-player tracking script does not work.

Because I don’t know how to use the vector.dot thing, I made a roundabout method.

There is a secondary part of an enemy that watches the player, and will change the direction of it’s parent depending on where they are. the direction is based upon it’s own rotation.

if(transform.rotation.y >= 0){
	if(transform.rotation.y < 45){
	direction = 1;
}}
else if(transform.rotation.y >= 45){
	if(transform.rotation.y < 135){
	direction = 2;
}}
else if(transform.rotation.y >= 135){
	if(transform.rotation.y < 225){
	direction = 3;
}}
else if(transform.rotation.y >= 225){
	if(transform.rotation.y < 315){
	direction = 4;
}}
else if(transform.rotation.y >= 315){
	if(transform.rotation.y < 360){
	direction = 1;
}}


if(direction == 1){
parent.renderer.material.mainTexture = tex1;
}if(direction == 2){
parent.renderer.material.mainTexture = tex2;
}if(direction == 3){
parent.renderer.material.mainTexture = tex3;
}if(direction == 4){
parent.renderer.material.mainTexture = tex4;
}

No matter where the player goes, the direction Stays at 1, despite the transform’s rotation in the inspector changing depending on where the player is.

When you are using “else if” it will only enter that conditional statement if the preceding related “if” statement was false. Since “transform.rotation.y >= 0” is always true, all the “else if” statements will be ignored. You could instead use:

if (transform.eulerAngles.y >= 0 && transform.eulerAngles.y < 45) etcetera…

edit on my answer:
Use transform.eulerAngles.y instead in this context, as that will return the angle in degrees.