How do i flip my Player in 2D when i got touch movement? I got Buttons to move but how do I flip the player now if i walk to the right cause my player faces to the left..?
here is my Player Script:
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed = 10, jumpVelocity = 10;
public LayerMask playerMask;
public bool canMoveInAir = true;
Transform myTrans, tagGround;
Rigidbody2D myBody;
bool isGrounded = false;
// Use this for initialization
void Start ()
{
myBody = this.GetComponent<Rigidbody2D>();
myTrans = this.transform;
tagGround = GameObject.Find (this.name + "/tag_ground").transform;
}
// Update is called once per frame
void FixedUpdate ()
{
isGrounded = Physics2D.Linecast (myTrans.position, tagGround.position, playerMask);
#if UNITY_ANDROID && !UNITY_IPHONE && !UNITY_BLACKBERRY && !UNITY_WINRT
Move(Input.GetAxisRaw("Horizontal"));
if(Input.GetButtonDown("Jump"))
Jump();
#endif
}
public void Move(float horizontalInput)
{
//Er klebt nicht mehr an den Waenden
if (!canMoveInAir && !isGrounded)
return;
Vector2 moveVel = myBody.velocity;
moveVel.x = horizontalInput * speed;
myBody.velocity = moveVel;
}
public void Jump()
{
if(isGrounded)
myBody.velocity += jumpVelocity * Vector2.up;
}
}