I have an enemy that moves along the ground, and I would like the enemy to change its direction. I am using a linecast to a gameobject that’s below it. My code seems to work in that the scale changes to -1 when on play, but it doesn’t actually change direction. It would be very much appericated if someone could tell me whats going on here.
This the code in Update:
transform.Translate (new Vector2 (_transform.localScale.x, 0) * moveSpeed);
// enemy turns around when gets to an edge
if (!Physics2D.Linecast (_transform.position, groundCheck.position, whatIsGround)) {
//facingRight = !facingRight;
Vector3 scalino = _transform.localScale;
scalino.x *= -1;
_transform.localScale = scalino;
print (_transform.localScale + " " + Time.time);