HeroMobility.cs 644 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
using UnityEngine;
using System.Collections;

public class HeroMobility : MonoBehaviour {
	public float playerSpeed = 1f;
	private Rigidbody2D playerRB;
	Animator anim;

	// Use this for initialization
	void Start () {
		playerRB = GetComponent<Rigidbody2D> ();
		anim = GetComponent<Animator> ();

	}
	
	// Update is called once per frame
	void Update () {
		Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
		playerMove (input);

	}


	void playerMove (Vector2 input){

		//Controls hero movement in all 8 directions
		playerRB.MovePosition((Vector2)transform.position + input*playerSpeed);

	}
}