Все, что я пытаюсь сделать, это когда враг поворачивается вокруг, его спрайт переворачивается, код ниже - это то, что мне удалось, но сейчас он переворачивается только после двух изменений в направлении, которое близко, но не то, что мне нужно. Пожалуйста, помогите.
[HideInInspector]
public bool facingRight = true;
public float speed;
Rigidbody2D rbody;
public float timer;
Animator anim;
public float directionx;
// Use this for initialization
void Start()
{
rbody = GetComponent<Rigidbody2D>();
StartCoroutine(Move(timer));
}
IEnumerator Move(float timer)
{
while (0 < 1)
{
Vector2 targetVelocity = new Vector2(directionx, 0);
rbody.velocity = targetVelocity * speed;
yield return new WaitForSeconds(timer);
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
Vector2 targetVelocity1 = new Vector2(-directionx, 0);
rbody.velocity = targetVelocity1 * speed;
yield return new WaitForSeconds(timer);
}
}
}