Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerMovement : MonoBehaviour {
- Rigidbody2D myRigidBody;
- Animator anim;
- float movementSpeed = 5f;
- // Use this for initialization
- void Start () {
- myRigidBody = GetComponent<Rigidbody2D> ();
- anim = GetComponent<Animator> ();
- }
- // Update is called once per frame
- void Update () {
- float horizontal = Input.GetAxisRaw ("Horizontal");
- anim.SetFloat ("speed", Mathf.Abs(horizontal));
- myRigidBody.velocity = new Vector2(horizontal * movementSpeed, myRigidBody.velocity.y);
- if (horizontal > 0) {
- transform.localScale = new Vector3 (1, transform.localScale.y, 1);
- } else if (horizontal < 0) {
- transform.localScale = new Vector3 (-1, transform.localScale.y, 1);
- }
- }
- }
Add Comment
Please, Sign In to add comment