Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerController : MonoBehaviour {
- public float maxSpeed = 4;
- public float jumpForce = 550;
- [HideInInspector]
- public bool lookingRight = true;
- private Rigidbody2D rb2d;
- private Animator anim;
- void Start () {
- rb2d = GetComponent<Rigidbody2D>();
- anim = GetComponent<Animator>();
- }
- void FixedUpdate ()
- {
- float hor = Input.GetAxis ("Horizontal");
- rb2d.velocity = new Vector2 (hor * maxSpeed, rb2d.velocity.y);
- if ((hor > 0 && !lookingRight) || (hor < 0 && lookingRight))
- Flip ();
- }
- public void Flip()
- {
- lookingRight = !lookingRight;
- Vector3 myScale = transform.localeScale;
- myScale.x*= -1;
- transform.localeScale = myScale;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement