Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- [RequireComponent(typeof(Rigidbody2D))]
- public class CharacterController2D : MonoBehaviour {
- public float speed;
- Rigidbody2D rb;
- void Start () {
- rb = GetComponent<Rigidbody2D>();
- }
- void Update () {
- rb.velocity = MovementInput * speed;
- }
- Vector2 MovementInput{
- get{
- int x = Input.GetKey(KeyCode.D) ? 1 :
- Input.GetKey(KeyCode.A) ? -1 : 0;
- int y = Input.GetKey(KeyCode.W) ? 1 :
- Input.GetKey(KeyCode.S) ? -1 : 0;
- return new Vector2(x, y);
- }
- }
- /* Published for berkinakkaya.wixsite.com/blog */
- }
Advertisement
Add Comment
Please, Sign In to add comment