Я столкнулся с такой проблемой то что мой персонаж ходит но не поварачиваеться когда нужно . Вот скрипт
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
private float horizontalSpeed;
float speedX;
public float verticalImpulse;
Rigidbody2D rb;
bool isGrounded;
private bool facingRight = true;
void Start() {
rb = GetComponent<Rigidbody2D>();
}
public void LeftButtonDown()
{
speedX = -horizontalSpeed;
}
public void RightButtonDown()
{
speedX = horizontalSpeed;
}
public void Stop()
{
speedX = 0;
}
public void OnClickJump()
{
if(isGrounded)
rb.AddForce(new Vector2(0, verticalImpulse), ForceMode2D.Impulse);
}
void FixedUpdate () {
transform.Translate(speedX, 0, 0);
if (facingRight == false && horizontalSpeed > 0)
{
Flip();
}
else if (facingRight == true && horizontalSpeed < 0)
{
Flip();
}
}
void Flip()
{
facingRight = !facingRight;
transform.Rotate(0f, 180f, 0f);
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Ground")
isGrounded = true;
}
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.tag == "Ground")
isGrounded = false;
}
}