Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This Script uses Pixelplacement Plugin from Unity Asset Store.
- If you face any problem reach out to me.
- */
- using UnityEngine;
- using System.Collections.Generic;
- public class PlayerControl : MonoBehaviour
- {
- #region Readonly
- public readonly static Vector2
- Up = new Vector2(0, 1),
- Down = new Vector2(0, -1),
- Left = new Vector2(-1, 0),
- Right = new Vector2(1, 0);
- #endregion
- private void Update()
- {
- if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) Move(Right);
- if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) Move(Left);
- if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)) Move(Up);
- if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)) Move(Down);
- }
- void Move(Vector2 d)
- {
- d *= 0.5f;
- Vector2 dir;
- dir.x = d.x - d.y;
- dir.y = (d.x + d.y) / 2;
- Pixelplacement.Tween.Position(transform, (transform.position + (Vector3)dir), 0.25f , 0);
- }
- }
Add Comment
Please, Sign In to add comment