Guest User

Untitled

a guest
Oct 16th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerMovement : MonoBehaviour {
  6.  
  7. Rigidbody2D myRigidBody;
  8. Animator anim;
  9. float movementSpeed = 5f;
  10.  
  11. // Use this for initialization
  12. void Start () {
  13. myRigidBody = GetComponent<Rigidbody2D> ();
  14. anim = GetComponent<Animator> ();
  15. }
  16.  
  17. // Update is called once per frame
  18. void Update () {
  19.  
  20. float horizontal = Input.GetAxisRaw ("Horizontal");
  21. anim.SetFloat ("speed", Mathf.Abs(horizontal));
  22. myRigidBody.velocity = new Vector2(horizontal * movementSpeed, myRigidBody.velocity.y);
  23. if (horizontal > 0) {
  24. transform.localScale = new Vector3 (1, transform.localScale.y, 1);
  25. } else if (horizontal < 0) {
  26. transform.localScale = new Vector3 (-1, transform.localScale.y, 1);
  27. }
  28.  
  29. }
  30. }
Add Comment
Please, Sign In to add comment